frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

2048 with only 64 bits of state

https://github.com/izabera/bitwise-challenge-2048
96•todsacerdoti•3d ago

Comments

meta-level•5h ago
Wow,I have a bash script that just starts a docker container with some fancy arguments roughly the same LOC...
JoeOfTexas•5h ago
I too am impressed with his bash script. Simple and concise.
kinduff•5h ago
The LOC are really impressive and the implemention pretty smart. Thanks for sharing!
lotyrin•5h ago
I was thinking "wow, how do you do that?" but then I forgot you're not dealing with any possible value between 1 and 2048 in a cell, only the powers of 2, so significantly fewer possible board states. Very cool.

I feel people often miss opportunities to map between (potentially complex, high entropy) state spaces into simple linear sequences of possible states and then either use those sequences to store the complex state data as a simple number or use the state of a system to encode data of some kind.

Like, if you use a limited 7-bit character set encoding for text and map that to a number in a sequence of possible orderings of a deck of 52 cards, you can store 32 characters (conveniently sized for passwords you might not want people to know are passwords).

carra•5h ago
It is worth mentioning that in the original game you can choose to keep going after you reach 2048. This game had to remove that option to achieve a 64bit state. Still, a clever implementation.
enriquto•5h ago
> keep going after you reach 2048. This game had to remove that option to achieve a 64bit state.

Since 15^16 < 2^64, you can still use a 64 bit state to reach 2^15=32768, which does not seem to be reachable in practice (the previous state would fill the whole board!)

ToValueFunfetti•4h ago
I'm not sure how the math works out, but some googling suggests that 32768 is achievable in practice while 65536 and 131072 are theoretically possible but have only been achieved with undos.

edit: Explanation of the 131072 cap: https://puzzling.stackexchange.com/questions/48/what-is-the-...

Also, in one of the answers there someone claims to have achieved 65536 in practice

sltkr•4h ago
You need 16^16 for 32768 because 0 is used to represent an empty tile (2^0 = 1 is not used) which is exactly equal to 2^64.

The state in this implementation also stores a random seed (between 0 and 99, exclusive), so using 16^16 for the state would leave nothing for the random seed.

nneonneo•5h ago
Cool! I used a similar trick in my 2048 AI: https://github.com/nneonneo/2048-ai. In my case I allow the tiles to go all the way up to 32768, so I just have one tile per nybble.

Using this representation is great: it lets me pack a whole gameboard into a single machine register, which makes it super efficient. In this case I see that you’re able to pack in a seed value to enable replayability - neat!

kccqzy•1h ago
Love the fact that you refer to your program as AI. We need more people to use AI to refer to non-LLM technologies lest the term be redefined.
enriquto•5h ago
Total number of states = 11^16, assuming you don't reach 2048, just like you don't actually kill the king in chess.

Now log_2(11^16)=55.34, thus 56 bits are sufficient. That's tight!

nine_k•3h ago
Encode them in CJK and combining Unicode characters, to keep the visual representation as short as possible.
eurleif•5h ago
To me, the impressive part is implementing it in under 200 lines of bash script, not implementing it with only 64 bits of state. Nothing clever is required for 64 bits of state: a cell has 12 possible states (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, and empty), which can be expressed in 4 bits, and 4*4*4 = 64.
charcircuit•4h ago
>a cell has 12 possible states

There is 18 states. The final possible board state is 16 increasing power of 2s starting at 4, since it's possible for a tile to spawn in as 4. Then you also need states for 2 and empty making for a total of 18.

Lerc•4h ago
That's a special case. You could have a single bit for special case mode and then very few bits to say what happened.

Usually you can encode special states in a more compact form because the type of specialness is additional information meaning the single special bit is all you need to grow by.

A bloated form for the final state would be a bit to indicate specialness, 7 bits for specialness mode. End state mode is encoded as the turn before plus direction. So adding 10 bits in all, there's almost certainly enough in the knowledge that it is an end state to encode the board in 10 bits fewer, eliminating all expansion except for the specialness bit.

pixelpoet•3h ago
There are*
nine_k•4h ago
13 possible states, because the empty state is important, too. But they fit nicely into 4 bits.

It would be mildly interesting to super-package the state into the theoretically smallest possible amount of bits: 13 * 16 = 665416609183179841 possible states, which is approximately 2 * 59.2, so 60 bits would be enough, with some margin. A whole hex digit shorter!

eurleif•4h ago
I included empty in my count.
sltkr•4h ago
That's what the code already does. It packs 16 fields into a base 12 representation that takes up 57.36 bits and uses the remaining 6.64 bits to store a random seed between 0 and 99 (exclusive).
kccqzy•1h ago
The board rotation trick is very nice to achieve the short code length!

        w) squish ;;
        a) rot; squish; rot; rot; rot ;;
        s) rot; rot; squish; rot; rot ;;
        d) rot; rot; rot; squish; rot ;;
izabera•53m ago
thank you i was so proud of it lmao
mark_undoio•2h ago
Always fun to see what izabera has come up with - every single time I'm somewhere between delighted and terrified to see what she's made the computer do this time!
Normal_gaussian•2h ago
YOLO install command

  curl -fsSL https://raw.githubusercontent.com/izabera/bitwise-challenge-2048/develop/2048.bash -o "$HOME/bin/2048" && chmod +x "$HOME/bin/2048" && 2048
teaearlgraycold•1h ago
You could pin to a commit for safety
Normal_gaussian•19m ago
Thats a fair point

    curl -fsSL https://raw.githubusercontent.com/izabera/bitwise-challenge-2048/413abf35be0f47c4947a5ebd6d581355383041e1/2048.bash -o "$HOME/bin/2048" && chmod +x "$HOME/bin/2048" && 2048
bvanderveen•16m ago
Like others I found the concise implementation to be impressive! I have noticed a bug though. Using the "drive into the corner" strategy (I keep the high tile in the bottom left) sometimes the top left tile randomly gets a smaller value (e.g., goes from 16 -> 4) when I slide to the left.

Mechanical Watch: Exploded View

https://fellerts.no/projects/epoch.html
594•fellerts•10h ago•86 comments

I wrote my PhD Thesis in Typst

https://fransskarman.com/phd_thesis_in_typst.html
134•todsacerdoti•4h ago•66 comments

Using Home Assistant, adguard home and an $8 smart outlet to avoid brain rot

https://www.romanklasen.com/blog/beating-brainrot-by-button/
89•remuskaos•4h ago•46 comments

Finding a billion factorials in 60 ms with SIMD

https://codeforces.com/blog/entry/143279
25•todsacerdoti•2h ago•0 comments

Cross-Account and Cross-Region Backups with AWS Backup (and Friends)

https://tylerrussell.dev/2025/06/20/cross-account-and-region-backups-with-aws-backup-and-friends/
13•terussell85•2d ago•3 comments

Hawaii Highways

http://www.hawaiihighways.com/
16•yakattak•2h ago•3 comments

Optifye.ai (YC W25) – Founding Back End Engineer

1•Vivaan_Baid•21m ago

Klein Bottle Amazon Brand Hijacking (2021)

https://www.kleinbottle.com/Amazon_Brand_Hijacking.html
89•sebg•6h ago•24 comments

Git Notes: Git's coolest, most unloved­ feature (2022)

https://tylercipriani.com/blog/2022/11/19/git-notes-gits-coolest-most-unloved-feature/
432•Delgan•16h ago•109 comments

Adobe Project Indigo is a new photo app from former Pixel camera engineers

https://www.engadget.com/apps/adobe-project-indigo-is-a-new-photo-app-from-former-pixel-camera-engineers-213453207.html
8•bookofjoe•2d ago•1 comments

Interview with Francine Prose on early-1970s San Francisco [audio]

https://www.laphamsquarterly.org/content/episode-3-francine-prose
41•keiferski•5h ago•6 comments

Radio Garden

https://radio.garden/?2025
32•LeoPanthera•3h ago•6 comments

2048 with only 64 bits of state

https://github.com/izabera/bitwise-challenge-2048
97•todsacerdoti•3d ago•26 comments

LibRedirect – Redirects popular sites to alternative privacy-friendly frontends

https://libredirect.github.io
381•riffraff•19h ago•93 comments

We’ve had a Denisovan skull since the 1930s—only nobody knew

https://arstechnica.com/science/2025/06/the-controversial-dragon-man-skull-was-a-denisovan/
49•Bluestein•3d ago•12 comments

How to negotiate your salary package

https://www.complexsystemspodcast.com/episodes/how-to-negotiate-your-salary-package/
203•surprisetalk•4d ago•177 comments

FreeBSD Kernel Modules Pkg(8) Repositories

https://vermaden.wordpress.com/2025/06/22/freebsd-kernel-modules-pkg8-repositories/
24•todsacerdoti•5h ago•3 comments

The cultural decline of literary fiction

https://oyyy.substack.com/p/the-cultural-decline-of-literary
111•libraryofbabel•9h ago•206 comments

Show HN: Turn a paper's DOI into its full reference list (BibTeX/RIS, etc.)

https://references.mireklzicar.com
30•mireklzicar•6h ago•10 comments

TPU Deep Dive

https://henryhmko.github.io/posts/tpu/tpu.html
370•transpute•22h ago•72 comments

Kilauea volcano errupts, lava more than 1k feet high [video]

https://www.youtube.com/watch?v=oG5zz9Sjw3E
65•asix66•2d ago•33 comments

I was surprised by how simple an allocator is

https://tgmatos.github.io/allocators-are-for-monkeys-with-typewriters/
77•gilgamesh3•3d ago•30 comments

How fast are Linux pipes anyway?

https://mazzo.li/posts/fast-pipes.html
182•keepamovin•17h ago•22 comments

Dynamic YAML with Python computed properties for fusing API workflows and SQL

https://sequor.dev/
8•maxgrinev•2d ago•3 comments

Why do all browsers' user agents start with "Mozilla/"? (2008)

https://stackoverflow.com/questions/1114254/why-do-all-browsers-user-agents-start-with-mozilla
88•nan60•5h ago•42 comments

Using an $8 smart outlet to avoid brainrot

https://www.neilchen.co/blog/kasa
102•NWChen•12h ago•62 comments

Low-Temperature Additive Manufacturing of Glass

https://www.ll.mit.edu/research-and-development/advanced-technology/microsystems-prototyping-foundry/low-temperature
102•LorenDB•4d ago•18 comments

Mbake – A Makefile formatter and linter, that only took 50 years

https://github.com/EbodShojaei/bake
211•rainmans•3d ago•99 comments

Remote MCP Support in Claude Code

https://www.anthropic.com/news/claude-code-remote-mcp?campaignId=13926158&source=i_email&medium=email&content=Oct2024AnalysisTool&messageTypeId=140367
150•surprisetalk•4d ago•71 comments

Show HN: Luna Rail – Treating night trains as a spatial optimization problem

https://luna-rail.com/en/home-2
111•ant6n•4d ago•59 comments