It may be slightly optimized, but it does the trick:
Assumption - the input consists of (only) two binary numbers (with leading 0, so 01 instead of 1 and 00 instead of 0), separated by an empty character (_). The result is a leading binary number representing x * y mod 4 ..
Transition table (state current_symbol new_symbol move_direction new_state):
0 0 0 r 0 0 1 1 r 0 0 _ _ r 1 1 0 0 r 1 1 1 1 r 1 1 _ xr 2 2 _ 0 r 3 3 _ 0 l 4 4 0 0 l 4 4 xxl 5 5 0 0 l 5 5 1 1 l 5 5 xxl 5 5 _ _ l 6 6 1 0 r 7 6 0 0 l 16 7 0 0 r 7 7 1 1 r 7 7 _ _ r 7 7 xxl 8 8 0 0 l 9 8 1 1 r 10 9 0 0 l 5 9 1 1 r 14 10 xxr 10 10 0 0 r 11 10 1 1 r 11 11 0 1 l 12 11 1 0 l 18 12 0 0 l 12 12 1 1 l 12 12 xxl 13 13 0 0 l 9 13 1 1 l 9 14 0 0 r 14 14 1 1 r 14 14 xxr 15 15 0 1 r 5 15 1 0 r 5 16 0 _ r 19 16 1 0 r 17 17 0 1 r 7 18 0 1 l 12 18 1 0 l 12 19 0 _ r 19 19 1 _ r 19 19 _ _ r 19 19 x _ r halt
Description of the rough state:
- 0 move to the right of the first number (right)
- 1 move to the right of the second number (and end - add x) -
- 2 write the first zero result
- 3 write the second zero result
- 4 go to x (left)
- 5 move to the right of the first number (left)
- 6 decrements from right to one
- 7 decremented - now copy number - move to the left digit of the correct number
- 8 read the left digit of the correct number
- 9 read the right digit of the right number
- 10 right digit of the right number was 1 - move to the right of the result to increase
- 11 increment result
- 12 go to x
- 13 Go to the right digit of the right number.
- 14 go to the left digit of the result to enlarge
- 15 increase the right number (note - since this is mod 4, we just flip)
- 16 when trying to reduce the left number - the right digit was 0 - check if 00?
- 17 we reduced the left number by 2, now increase to total -1
- 18 when adding the result of the left digit 0 - transfer
- 19 cleaning
decPL source share