I'm pretty new to code golfing, but I recently came across a guy on Kattis that consistently has exactly 5 character Bash solutions for some problems. For example, here is a leaderboard showing his 5 character solution: https://open.kattis.com/problems/summertrip/statistics
Anyone have any idea how he's able to do this? I'm itching to find an answer, any help is greatly appreciated
-
2\$\begingroup\$ I think this might be borderline off topic. My opinion (as an individual) is that this is on topic, since it is asking about how a particular problem could be solved in a certain number of bytes. It does seem that maybe there is some "cheating" involved, but I don't think that makes it off topic. \$\endgroup\$Wheat Wizard– Wheat Wizard ♦2025年09月04日 02:27:14 +00:00Commented Sep 4 at 2:27
-
1\$\begingroup\$ This question is similar to: Tips for golfing in Bash. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. \$\endgroup\$IY5dVSjABEeV– IY5dVSjABEeV2025年09月04日 02:57:59 +00:00Commented Sep 4 at 2:57
-
9\$\begingroup\$ There are several hundred problems on that site where the shortest solution is 5 bytes. Every one I've looked at has a 5 byte Bash 'solution' by the same user. I don't think I'm going out on a limb by suggesting that this is blatant cheating/exploitation of the controller rather than any exhibition of golfing wizardry. \$\endgroup\$Dingus– Dingus2025年09月04日 05:45:02 +00:00Commented Sep 4 at 5:45
-
1\$\begingroup\$ I'm pretty sure kattis only displays on the leaderboard if your solution is accepted. But clearly this guys is cheating somehow, maybe running some sort of bash script that isn't included in the character count? \$\endgroup\$Donald Trump– Donald Trump2025年09月04日 13:51:51 +00:00Commented Sep 4 at 13:51
-
3\$\begingroup\$ I have contact to one of the main devs at Kattis and can point this out to him if you so wish. \$\endgroup\$Adám– Adám2025年09月04日 16:03:14 +00:00Commented Sep 4 at 16:03
1 Answer 1
TL;DR:
Kattis did not count the length of the filenames. So, we could encode the actual solution in the name of multiple files.
This strategy worked until Sep 2025 when Kattis devs fixed it.
I will give you some examples:
2 bytes for digitswap
Using one main file + one extra file to save 1 byte:
main.sh: r*
rev: (empty)
It triggers the "rev" command.
2 bytes for greetings2
main.sh: s*
sed: (empty)
szezeezg: (empty)
The actual command is:
sed szezeezg
Which is equivalent to:
sed s/e/ee/g
2 bytes to print an arbitrary number/identifier
sz.sh: s*
sed: (empty)
sy..y<CONTENT>y: (empty)
It reuses the content of the main file to create the output.
4 bytes for velkomin
main.sh: s*
sed: (empty)
syVyVELKOMINy: (empty)
sz: V!
It replaces "V!" as "VELKOMIN!"
5 bytes general solution using perl
sz.sh: s*|p*
sed: (empty)
sy.....y<CODE>y: (empty)
perl: (empty)
6 bytes general solution for interactive problems
sz.sh: `s*`
sed: (empty)
sx....x-e<CODE>x: (empty)
sy: p*
perl: (empty)
It requires extra skills (v-strings, bareword, etc) to write perl code within the allowed characters for filenames.