Skip to content

Instantly share code, notes, and snippets.

name: CSC 404 - COPY String (v2)
source code: |-
input: '1011#'
blank: ' '
start state: seekDigit
table:
seekDigit:
'0': {write: X, R: have0}
'1': {write: X, R: have1}
'#': {R: accept}
name: CSC 404 - COPY String
source code: |
input: '1011#'
blank: ' '
start state: seekDigit
table:
accept:
seekDigit:
'0': {write: 'X', R: have0}
'1': {write: 'Y', R: have1}
name: 'CSC 404 - Zeros followed by an equal number of 1s (v2) '
source code: |-
#Zeros followed by an equal number of 1s
# L = {0^k1^k: k=0,1,2,...}
# Here we speed things up by crossing of half the 0s and half the 1s each pass. At each step we make sure the 0s and 1s are both even or both odd. If we ever have a mismatch - Reject
input: '0000011111'
#input: '0000000011111111'
#input: '0001111'
#input: '0000111'
name: CSC 404 - Power of 2 Number of Zeros
source code: |+
#Power of 2 number of zeros!
#Each pass we cross off half of the 0s. If we ever find an odd number of 0s - Reject!
input: '00000000'
#input: '0000'
#input: '00000' #Should Fail!
#input: '000000' #Should Fail!
blank: ' '
name: CSC 404 - Zeros followed by an Equal Number of 1s
source code: |
#Zeros followed by an equal number of 1s
# L = {0^k1^k: k=0,1,2,...}
input: '000111'
#input: '0001111'
#input: '0000111'
#input: '00011101'
blank: ' '
name: CSC 404 - Unary Addition
source code: |-
# Unary Addition. f(n,m) = n + m.
input: '11111*111'
#input: '111*'
#input: '*111'
#input: '11111111111*1111111'
blank: ' '
name: CSC 404 - Identical Strings
source code: |+
# Accepts two equal binary strings separated by '#'
input: '00110#00110'
#Try 0#0, 0#01, 01#0, #
blank: ' '
start state: start
table:
accept:
name: CSC 404 - Binary String Reversal
source code: |
# Reverses a binary string
input: '001101'
blank: ' '
start state: seekEnd
table:
seekEnd:
[0,1]: {R: seekEnd}
name: CSC 404 - Binary Palindromes
source code: |+
input: '001100'
#input: '0010100'
blank: ' '
start state: start
table:
accept:
reject:
start:
name: Even Number of 0s and 1s
source code: |-
# Even Number of 0s and 1s
# Find a 0 when reading left to right. Then frind a 1 when reading right to left. Repeat.
input: '0000111' # try '010110'
#input: '010110'
#input: '111000'
blank: ' '
start state: seek0