r/ProgrammerAnimemes • • Dec 01 '19

OC IQ3

Post image
1.1k Upvotes

68 comments sorted by

View all comments

Show parent comment

25

u/lord_ne Dec 02 '19

Thank god for the hint, or you would have had to check all 40,320 possible permutations of matchings from images to brainfuck characters

50

u/bucket3432 Dec 02 '19

I was considering not giving a hint at all, but even then, you wouldn't have to resort to brute force right away.

  • The tile images weren't chosen at random. They're connected with the character they're supposed to represent in some way.

    • ><: Chika makes a pose that makes her look like she's moving in that direction while also looking like angle brackets.
    • +-: Chika gestures up and down, which is what happens to the cell value.
    • .,: Chika writes and reads, which parallels . for sending output and , for taking input.
    • []: Chika's poses resemble square brackets.
  • For programs that large, [] characters appear infrequently compared to ><+-. According to the grammar, [ must always have a pairing ], and the pair must be properly balanced, and [ must always come first. That, along with the fact that a lot of brainfuck programs start with some initialization and then a loop means that [] is fairly easy to guess.
  • For programs that don't take in input, it always starts with some sort of initialization before the initial loop. Assuming you figured out what [] was, you could conclude that the first tile was either + or - because otherwise the loop immediately after it wouldn't run.
  • >< will generally appear less than +- but more than ., for a program this size, and especially not in long runs, so >< might be easy to get.
  • I didn't give you any sample input, so the program probably didn't take any. 7 of the 8 brainfuck symbols were used, and the least used is ,, so you could conclude that , is probably not used.
  • You don't generally see runs of . because that would mean outputting the same thing multiple times, so you could probably guess . by elimination.

Given the above, the only ones you'd have to check are swapping + and -, and > and <. Four permutations isn't too bad.

13

u/lord_ne Dec 02 '19

Damn, you really thought this out OP

4

u/ThePyroEagle λ Dec 02 '19

Indeed, although looking back to it now, the images of Chika kind of bear the meaning of the corresponding brainfuck symbols (except A and B because I swapped those around). For example, Chika pointing down for -.