In my own Turing pseudocode:
- copy input A0B to Tape 2
- write 000010000 to Tape 3
- multiply the number on Tape 3 by A from Tape 2 by
- starting at the beginning of A
- writing 0 to Tape 4
- copying number 3 => 4
- moving forward once on Tape 3 (3++)
- going to step 3 unless A ends
- moving answer from Tape 4 to tape 3
- decrement the number B on Tape 2
- If B on Tape 2 isn't 0, go to step 2
- Copy the answer from Tape 3 to Tape 1
Here's the turing code that should work (tapes are like pointers, lowercase letters, input tape is i
):
# At the start for 2^3
# i: 000111011110000
# ^
_start_ -> *a = 0, start2
start2 [*i==0] -> i++, *a++ = 0, *b++ = 0, start4
start2 [*i==1] -> i++, *a++ = 1, start2
start4 [*i==0] -> *b-- = 0, b--, initc
start4 [*i==1] -> i++, *b++ = 1, start4
initc -> *c++ = 0, *c++ = 1, *c++ = 1, *c-- = 0, mult
# example
# i: 00011101111000
# ^
# a: 001110000
# ^
# b: 001111000
# ^
# c: 00011000
# ^
mult[*b==0]: lastcpy
mult[*b==1]: b--, *d++ = 0, *d++ = 1, rewa
rewa[*a==0]: a++, a++, multcpy
rewa[*a==1]: a--, rewa
multcpy[*c==1]: c++, multcpy2
multcpy[*c==0]: multcpy3
multcpy2[*a==0]: multcpy
multcpy2[*a==1]: *d++ = 1, multcpy2
multcpy3: *d-- = 0, *c = 0, cpydtoc
cpydtoc[*d==1]: d--, *c++ = 1, cpydtoc
cpydtoc[*d==0]: *c-- = 0, mult
lastcpy[*c==1]: *i++ = 1, c--, lastcpy
lastcpy[*c==0]: *i = 0, _finish_
# Should end with
# i: 00011101111011111111100
# ^
Please check for errors :)