Share your repls and programming experiences

← Back to all posts
Snake game coded in 1024 bytes
henry_lv (4)

The classic game of snake using exactly 1024 bytes of code.

WASD to move.
Reload the page to restart.

But don't turn to fast or you will die (This is a bug but I can't fix it with out going over 1024 bytes :( )

Have fun playing!

PS. if you want to look at the code, you might want to pretty print it. And sorry for the obfuscation of the variable names, it makes the game smaller.

DynamicSquid (4929)

Nice! But how'd you count the number of bytes? Do you just look at the repl file size? Or is there another way in JS?

henry_lv (4)

@DynamicSquid there were two ways I used, copying it into python and finding the length of the string (which is also the byte count 1 char == 1 byte)

>>> x = """paste code here"""
>>> print(len(x))
1024 (or what ever the string length is)

The other way I used was looking at the response headers from the server using chrome dev tools. Go to the Network tab

then click on

then you can see the content-length witch is the number of bytes the file is (excluding headers)

You can probably to the same thing in JS as in Python. Looking at the repl size does not work because it includes the size of the metadata in the repl size (I checked and it says 4 kb). You could also count by hand but, try counting to 1024 LOL.
Hope this helps.