; parity-bit.tm
; Append a bit to a binary string to have an even number of ones.
; Use two states to keep track of the parity of the ones found up to now
; To be copied and pasted onto the online simulator
; http://morphett.info/turing/turing.html
; The initial input must be formulated, for instance, as "100101".
; The initial state ("advanced settings" is "even").
; ------------------------------------------
; Initially, the state is even (no 1s have been found yet)
even 0 0 r even ; as long as we find a 0, the parity of 1s does not change
even 1 1 r odd ; once a 1 is found, the parity moves to odd
odd 0 0 r odd ; again, parity does not change
odd 1 1 r even ; parity changes every time we meet 1
even _ 0 r halt ; if a blank is found while in "even" state, append 0
odd _ 1 r halt ; if a blank is found while in "odd" state, append 1