2
\$\begingroup\$

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

Wheat Wizard
103k23 gold badges299 silver badges697 bronze badges
asked Sep 4 at 2:17
\$\endgroup\$
10
  • 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\$ Commented 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\$ Commented 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\$ Commented 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\$ Commented 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\$ Commented Sep 4 at 16:03

1 Answer 1

8
\$\begingroup\$

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.

answered Sep 26 at 12:45
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.