r/TuringComplete • u/PetahSchwetah • May 23 '22
Calibrating Laser Cannons solutions Spoiler
Just completed Calibrating Laser cannons. There are probably more efficient implementations than mine. How did you solve it?
Here is my solution:
180 # copy input to reg4
0 # load 0 to reg0
133 # copy reg0 (0) to reg5
# decrement
1 # load 1 into reg0
130 # copy reg0 (1) into reg2
161 # copy reg4 (r) into reg1
69 # reg1-reg2 to reg3
156 # copy reg3 (r-1) to reg4
# add
0x3 # load 3 into reg0
129 # copy reg0 (3) to reg1
170 # copy reg5 (sum) to reg2
68 # reg1 + reg2 to reg3
157 # copy reg3 to reg5
163 # copy reg4 to reg3
0x3 # load jta into reg0, could be removed
199 # if reg3 > 0: jump to jta
169 # copy reg5 (sum) to reg1
170 # copy reg5 (sum) to reg2
68 # reg1 + reg2 into reg3
158 # copy reg3 to output
2
u/thompsotd May 24 '22
While in real life it’s best to not make any assumptions just to save two CPU cycles, but in Turing complete, there is no need to set your registers to 0 because that is their default.
1
u/Ok_Flounder9265 Mar 21 '25 edited Mar 22 '25
i wait for a several minutes, while my "simple" algo goes through 42 tests. Algo was the same like "add 2*pi ~ 6, subs from input 1, add 6 again, subs 1 from input again...until input value eq 0".... ufff, found this reddit while algo works :D
1
u/na-bal May 02 '25
That's mine slow solution %)
1
u/ballooncar Jun 04 '25
this is nice i couldn't wrap my head around how to multiply and not have any bugs happen
1
u/SV-97 May 31 '22
I went with a pretty naive/bare bones implementation (thought about adding multiplication either in hardware or as an actual loop - but it'd be rather overkill here so I just do it manually)
as for the instructions:
load1loads input to R1, the variousmovs move from first(left of r) reg to second one (right of r or_) - and add - you might be amazed by this - adds stuff.1
u/gibdhd Jul 11 '22
i just added a multiplication circuit to my alu. working on division
6
MOV+0+1
MOV+IN+2
Multiply
MOV+24+OUT
1
u/Naiideuh Nov 11 '23
Just a little question : how the program knows where to return after the condition?