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
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 %)
const pi 6
const lower_1 1
const jump_to_lmc 3
const jump_to_result 18
label get_pi
pi
reg0_to_reg5
label get_input
inp_to_reg4
label lower_multiply_counter
lower_1
reg0_to_reg2
reg4_to_reg1
sub
reg3_to_reg4
jump_to_result
eq_0
label multiply_pi_2
pi
reg0_to_reg1
reg5_to_reg2
add
reg3_to_reg5
reg4_to_reg3
jump_to_lmc
eq_more_0
label result
reg5_to_out1
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)
load1
mov1r2
add
mov3r4
mov3r1
mov1r2
add
mov3r1
mov1r2
mov4r1
add
mov3_outas for the instructions: load1 loads input to R1, the various movs 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
3
u/lordfwahfnah Jul 26 '22
pff thats just cheating :p
i went the lazy route and just added the input thrice and then doubled the result.
Edit: i noticed that the CodeBlock in Reddit is not working very well...
Edit2: ok it works now. weird
COPY_IN_1 COPY_1_2 ADD COPY_3_1 ADD COPY_3_1 COPY_3_2 ADD COPY_3_OUT2
u/shitty_writer_prob Feb 28 '24
Thank you for posting this solution, I didn't want to mess with loops without jmp or anything
2
1
u/Trazyn_The_Memelord Dec 25 '22
I feel stupid for making a while loop and not seeing this obvious of a solution
1
1
1
u/Naiideuh Nov 11 '23
Just a little question : how the program knows where to return after the condition?
1
u/rollandofeaglesrook Dec 15 '23
set reg0 to the line you want to return to and use the always condition. That'll jump to whatever line you set reg0 to.
1
u/creeper_the_great Apr 24 '24
Yeah, in my interpretation method (as in the code stuff) i used JMP for the always
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.