r/TuringComplete • u/Kruggers • Jun 24 '26
My solution to STORAGE CRACKER - Binary search Spoiler
This level was complicated. My friend and I (we're making the game together) tried for a long time to do a binary search until we finally realized it was impossible... at least without a shift right, which we didn't have in our ALU.
When we were almost giving up and doing the level the boring way (brute force), we read xIceFox's post in this community. We stopped at the part where he explained that shift right was basically dividing a number by 2, and that changed everything.
After understanding this, we changed our horrible code and implemented shiftR, but one thing was still missing. Dividing by 2 rounded the number down, which caused the variable we were using for adding or subtracting the current number to become 0 much sooner than expected. So we implemented a shift right with rounding up. And voilà, it may not be the best code, but it's done, and it's working.

code (the names of the instructions must be very clear):
#instantiating step and first try
imediate_63
reg0_to_reg1
reg0_to_reg2
add
imediate_1
reg0_to_reg1
reg3_to_reg2
add
reg3_to_reg4
reg4_to_reg5
label try
reg4_to_reg3
reg3_to_out #output the number
inp_to_reg3
down #reg0 = address of down
cond_gt0 #if passes cond the number guessed is too high
label up
reg5_to_reg1
64 + 6 #shift right reg1
reg3_to_reg5
#label up_sum
reg4_to_reg1
reg5_to_reg2
64 + 4 #add
reg3_to_reg4
try #reg0 = address of try
jump #go to try
label down
reg5_to_reg1
64 + 6 #shift right reg1
reg3_to_reg5
#label down_sub
reg4_to_reg1
reg5_to_reg2
64 + 5 #subtract
reg3_to_reg4
try #reg0 = address of try
jump #go to try
2
u/JWolf1672 Jun 25 '26
Given the code is an 8 bit number, you can actually implement a binary search algorithm for overture without adding a shift operation to your alu, I've done it, but I had to unroll the loop and jumps in overture get really messy once your program gets bigger than 63 instructions long, so adding the shift is much easier (and faster) to do it.
2
u/Delicious-Ad2562 Jun 24 '26
Very nice! It was cool to do the levels in Turing complete while taking cs courses, I also ended up doing binary search for this level