[Community Puzzle] Squash Pi - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Westicles,validated by @ParzivalX,@Ben-42 and @VizGhar.
If you have any issues, feel free to ping them.

I misunderstood the constraints, reading the code size limit of 100K “characters” as 100K bytes. From that I decided that compression was impossible due to the thoeretical ideal of around 122KB to store 295,000 random decimal digits. I ended up solving the problem in C (with a hacky bash wrapper to link with libgmp) by borrowing a very fast open source Chudnovsky implementation built on the GNU BMP library. It computed 300,000 digits from scratch in well under a second.

My solution might be good for code golf at around 16KB of code :).

After seeing that the intent was to allow 100K unicode characters, I will do another implementation…

I’ve implemented a solution that works on my local machine with digits encoded into a single quoted Unicode string (all characters in the string are in the range that requires a 4-byte UTF-8 encoding, so there are 20 bits of usable data in each Unicode character). The source file is 201,179 bytes long but I have verified that it only contains 54,155 Unicode characters using wc:

$ wc -m -c solution.py
 54155 201179 solution.py

However, when I copy/paste the program from my IDE into the Codingame web UI, everything looks good but I am unable to run a verifier or submit because it says my program is > 100,000 characters. I’ve tried copying from vscode on Ubuntu and macOS, and trying different browsers. I tried adding a UTF-8 BOM at the top of the file. Nothing works for me. Any suggestions?

Some discussion here: Coding Games and Programming Challenges to Code Better

1 Like

That’s helpful… I was trying to get the most bits per Unicode character (20) which I got by using code points in the range U+010000 to U+10FFFF. That minimizes the number of characters. However, per the link you provided, CodingGame doesn’t actually count characters, it counts wchars (16-bit words when the document is encoded with UTF-16).

In UTF-16, Unicode code points U+010000 to U+10FFFF are encoded as two 16-bit words, so CodingGame counts them as two characters even though they are actually a single character.

I think this detail is significant and misleading enough that maybe it should be pointed out somewhere…? The limit is not 100,000 characters, it is 200,000 bytes when encoded as UTF-16.

Thanks much for the help.

1 Like