# Converts a unary string to the corresponding binary number (i.e., converts n # 1's to the binary representation of n). # Input: $1^n # Output: $1^n$n-in-binary Q = {start, setupr, setup, setupl, loop, add1, skip, inc, one, shift, done, tidy, move, halt} I = start F = halt G = {0, 1, $, b} S = {1, $} D = {(start, $, setupr, $, R), (setupr, 1, setupr, 1, R), (setupr, b, setup, $, R), (setup, b, setup, 0, L), (setup, $, setupl, $, L), (setupl, 1, setupl, 1, L), (setupl, $, loop, $, R)*, (loop, $, tidy, $, L), (loop, 1, add1, b, R), (add1, 1, add1, 1, R), (add1, $, skip, $, R), (skip, 0, skip, 0, R), (skip, 1, skip, 1, R), (skip, b, inc, b, L), (inc, 0, done, 1, L), (inc, 1, inc, 0, L), (inc, $, one, $, R), (one, 0, shift, 1, R), (shift, 0, shift, 0, R), (shift, b, done, 0, L), (done, 0, done, 0, L), (done, 1, done, 1, L), (done, $, done, $, L), (done, b, loop, b, R)*, (tidy, b, tidy, 1, L), (tidy, $, move, $, R), (move, 1, move, 1, R), (move, $, halt, $, R)}