algo/baby-game-revisited
13 solves / 495 points
Writeup by Aryan
I cheesed this problem, so if you want an actual writeup, look somewhere else.
The problem statement is quite similar to baby-game
except now Red Panda can move one or two squares. Caring Koala is still constrained to a max move of one square.
I started taking a look at this problem when there was less than an hour left in the CTF, and I knew I would not be able to solve it, so I started thinking outside the box.
This time, n <= 25, which presents an interesting opportunity to reverse engineer the cases!
This is possible because of a few factors.
The judge does not randomize test cases.
The judge shows the result of all test cases.
The judge shows the amount of test cases.
The judge distinguishes between Wrong Answer and Runtime Error.
See the following submission:
The code 5/0
will result in a Runtime Error, which we can distinguish from a Wrong Answer. We can now figure out which cases have input values of n = 3.
After figuring out the input n's for all cases, we can try bruteforcing small x in the expressions "Red Panda {x}" and "Caring Koala {x}" to figure out the cases that map to the input n's. Here's an example:
We get this output from the above script:
Since n <= 25, one can intuitively assume x will be pretty small too, and that turns out to be true, as the largest x ended up being 64 for a case when n=24. I came across an interesting insight here -- namely, that x is always even whenever Red Panda wins -- and there is probably some nice proof, but I was too lazy to think about it.
Once we have the input n and output answer for each case, we are almost ready to write our code. All we need to do is figure out some constraints on a, b, c, and/or d for the scenarios when multiple cases have the same n. We use an approach similar to prior scripts, executing runtime error if certain criteria are met. Finally, we put it all together.
Flag: vsctf{totally_not_a_dynamic_flag_318de8aa7b123ee9}
Last updated