Live data from Hacker News

Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

alexanderpruss.blogspot.com

31–40 of 170 posts

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#31
post #26

$ grep '^[a-z]\{5\}$' /usr/share/dict/words | python -c ' > from sys import stdin > from os import write > N = 26 ** 5 > data = bytearray((N+7)//8) > for l in stdin: > b = 0 > for c in l.strip(): > b *= 26 > b += ord(c)-ord("a") > data[b//8] |= 1 write(1, data) > ' | gzip | wc -c 12126 decompression code costs extra. Though I imagine someone has a small gunzip implementation somewhere.

No post body was provided.

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#32
post #26

$ grep '^[a-z]\{5\}$' /usr/share/dict/words | python -c ' > from sys import stdin > from os import write > N = 26 ** 5 > data = bytearray((N+7)//8) > for l in stdin: > b = 0 > for c in l.strip(): > b *= 26 > b += ord(c)-ord("a") > data[b//8] |= 1 write(1, data) > ' | gzip | wc -c 12126 decompression code costs extra. Though I imagine someone has a small gunzip implementation somewhere.

Zlib's implementation, at least, requires more working RAM (~40 KB) than the Game Boy has (8 KB). https://github.com/madler/zlib/blob/master/zconf.h

        The memory requirements for inflate are (in bytes) 1 

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#33
I haven't done any noodling with compression in some time and I'm tempted to sit down and try this. But I think he must be using a different list than I can find because the numbers don't quite add up.

Any time you are tasks with crushing the living daylights out of an unordered list, always, always look at suffix sorting as an option. It might not work out as useful, but it's frequently worth the cost of checking.

I will say that given that a delta encoding was settled on, bitpacking the words first is probably a mistake, and multiplication should have been used instead. For instance using multiplication you can store the words in 24 bits without chopping off the first character and using pointers to them. That may seem a small difference but it makes the deltas he's looking at narrower. So instead of choosing 8 words in 8 bytes versus 10 words in 8 bytes, it could be 8 vs 11, possibly 12.

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#34
post #32
post #26

$ grep '^[a-z]\{5\}$' /usr/share/dict/words | python -c ' > from sys import stdin > from os import write > N = 26 ** 5 > data = bytearray((N+7)//8) > for l in stdin: > b = 0 > for c in l.strip(): > b *= 26 > b += ord(c)-ord("a") > data[b//8] |= 1 write(1, data) > ' | gzip | wc -c 12126 decompression code costs extra. Though I imagine someone has a small gunzip implementation somewhere.

Zlib's implementation, at least, requires more working RAM (~40 KB) than the Game Boy has (8 KB). https://github.com/madler/zlib/blob/master/zconf.h The memory requirements for inflate are (in bytes) 1

This example above is the entire dict file, not the wordle file, so it might be worth looking at this.

I'd have to check the version history, but while 15 bits is the default it's also the maximum, and you can go down to 8. Hardware has gotten a lot faster.

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#36

And far better than gzip compression. Nice work. My takeaway is that context matters - this is not General Purpose Compression, but compression made specifically for this case. Good Stuff.

Is task specific compression a thing in real life practical software engineering? As far as reducing data loads go I only came across the keyword "SQL optimization".

I have designed task specific data structures/compression oriented around memory efficiency. In my experience this starts to crop up when datasets get big enough to trigger cost for performance sensitivity. This is especially true for SaaS offerings, where e.g. an ability to stay under the next RAM doubling can result in serious hosting savings.

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#37
post #26

$ grep '^[a-z]\{5\}$' /usr/share/dict/words | python -c ' > from sys import stdin > from os import write > N = 26 ** 5 > data = bytearray((N+7)//8) > for l in stdin: > b = 0 > for c in l.strip(): > b *= 26 > b += ord(c)-ord("a") > data[b//8] |= 1 write(1, data) > ' | gzip | wc -c 12126 decompression code costs extra. Though I imagine someone has a small gunzip implementation somewhere.

[deleted]

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#38
post #26

$ grep '^[a-z]\{5\}$' /usr/share/dict/words | python -c ' > from sys import stdin > from os import write > N = 26 ** 5 > data = bytearray((N+7)//8) > for l in stdin: > b = 0 > for c in l.strip(): > b *= 26 > b += ord(c)-ord("a") > data[b//8] |= 1 write(1, data) > ' | gzip | wc -c 12126 decompression code costs extra. Though I imagine someone has a small gunzip implementation somewhere.

I think you'll find if you use the real dict that your compression numbers are much worse. I got around 25k using a list I hunted up.

Re: Game Boy Wordle clone: How to compress 12972 five-letter words to 17871 bytes

#40

Over on http://golf.horse/ there are leaderboards for finding the smallest Javascript programs that output various word lists, including the Wordle list. I've found it to be a fun and educational challenge. I would be excited to see more submissions!

Interesting that page suggests that the wordle dictionary is 'at most 11.11 bits per word', which works out to 18015 bytes, slightly higher than was achieved here.

Golf.horse is measuring the payload plus the compressor, which I don't believe the author is doing, and is important when trying to be objective about the relative strength of solutions. Otherwise you can store the entire file out of band in the compressor, emit 1 bit in the output file, and then the compressor just returns the expected value on 1 and throws an error on 0 saying the file was corrupt.

Post reply on HN