This is a Sudoku that is also a Brainfuck program.

The standard rules of Sudoku apply. The same symbol can not appear twice in the same row, column, or 3x3 box.

The grid should also form a functioning Brainfuck program. There are two requirements, the program must halt, and it must produce the correct output. Here is an online interpreter for testing.

The program should, when given the input "BrainFuck", output "Crÿinl".

Char B   r   a   i   n   F   u   c   k
Hex  42  72  61  69  6E  46  75  63  6B
Dec  66 114  97 105 110  70 117  99 107

Char C   r   ÿ   i   n   l
Hex  43  72  FF  69  6E  6C
Dec  67 114 256 105 110 108

For visibility, the period are replaced with an exclamation mark, and a comma with a question mark.

Also, brackets cannot be balanced by the constraints of sudoku, so I am using the symbols [{. Whichever one appears first on a line is treated as an open bracket, and the second one is treated as a closing bracket.

# is not a valid command, so it is a no-op and does nothing.

Brainfuck operates on an infinite* array of memory cells, each initially set to zero. There is a pointer, initially pointing to the first memory cell. The commands are:

Command Description
> Move the pointer to the right
< Move the pointer to the left
+ Increment the memory cell at the pointer
- Decrement the memory cell at the pointer
. ! Output the character signified by the cell at the pointer
, ? Input a character and store it in the cell at the pointer
[ Jump past the matching ] if the cell at the pointer is 0
] Jump back to the matching [ if the cell at the pointer is nonzero
# Do nothing and continue to the next command

* May only be 30,000 bytes


I believe this is the solution (apologies in advance, not sure how best to format this):


Edited to include explanation of how I arrived at the solution:

I first ignored the brainfuck aspect of the puzzle and just tried solving it like a normal sudoku. I got to a certain point where the grid was probably about halfway full and I couldn't progress any further with normal deduction.

From there I looked at the candidates for the top row. I unfortunately didn't save the exact state it was in at that point, but basically IIRC the first three squares in the top row were some combination of >, + and ?. Permuting those and thinking through what the brainfuck output would be, I guessed that these would be ? (input the B), + (increment B to C), and > (move pointer to the right).

With those guesses in place I was able to fill in another bunch of cells using standard Sudoku logic. In particular at that point I believe the entire second row was filled in, and reading the brainfuck allowed me to fill in the rest of the top row to complete the first two lines of code that would produce the required output. At that point I was able to finish the rest of the puzzle like a normal Sudoku, and confirmed in the provided interpreter that the resulting code worked as required.

  • 3
    $\begingroup$ Could you provide any logic/progress pictures? Answers to [grid-deduction] puzzles are generally expected to "show their work". $\endgroup$ – bobble May 7 at 14:12
  • $\begingroup$ I've edited your answer to use pre html-tags, for preformatted mono-spaced font. AFAIK that's the only way to do it when inside a spoiler. $\endgroup$ – Jaap Scherphuis May 7 at 14:13
  • $\begingroup$ @bobble Thanks, I've updated my answer with an explanation. Jaap thank you for the editing help. $\endgroup$ – SQLnoob May 7 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.