######################
#  LEAVE THIS TOP PORTION INTACT
require_relative 'turing_machine'

unless ARGV.size == 1
  STDERR.puts "Usage: simulate_turing_machine <input string>"
  exit(-1)
end

# convert string into list of symbols
input_string = ARGV.first.split(//).map{ |ch| ch.intern }

machine = TuringMachine.new
machine.start_state = :start
machine.accepting_states << :finish

# define trace map
map = {
  :blank => '.',
  :B     => 'b',
  :s    => 's',
  :l     => '1',
  :o     => '0',
  :L     => 'L',
  :R     => 'R'
}
#CONVERTER: accepts any inputs in the form BBxxxByyyBzzz 
# and returns ..xxx.yyy.zzz with head at first word

machine.transitions[[ :start, :B    ]] = [ :blank, :start ]
machine.transitions[[ :start, :blank ]] = [:R, :statei]

machine.transitions[[ :statei, :B ]] = [:s, :statej]

machine.transitions[[ :statej, :B    ]] = [ :R, :statej ]
machine.transitions[[ :statej, :s    ]] = [ :R, :statej ]
machine.transitions[[ :statej, :o    ]] = [ :R, :statej ]
machine.transitions[[ :statej, :l   ]] = [ :R, :statej ]
machine.transitions[[ :statej, :blank    ]] = [ :L, :statek ]

machine.transitions[[ :statek, :o ]] = [ :L, :statek ]
machine.transitions[[ :statek, :l ]] = [ :L, :statek ]
machine.transitions[[ :statek, :s ]] = [ :blank, :statem ]
machine.transitions[[ :statek, :B ]] = [ :blank, :statel ]

machine.transitions[[ :statel, :blank ]] = [ :L, :statek ]

machine.transitions[[ :statem, :blank    ]] = [ :R, :state1]

####################################

#generic start line:            machine.transitions[[ :state1, :C  ]] = [:A, :state ]
#generic program line:    machine.transitions[[ :stateN, :C  ]] = [ :A, :stateN ]
#generic end line:             machine.transitions[[ :stateN, :C  ]] = [ :A, :finish ]

#:C is a content: ':blank', ':o', ':l'; :A is an action:  ':blank', ':o', ':l', ':L', ':R'; :stateN adds a number - as ':state125'

#YOUR PROGRAM STARTS HERE WITH :state1, ENDING AT :finish



###############################
# LEAVE THIS PORTION INTACT
# run simulation
machine.simulate(input_string, map)



