lib/automata/nfa.rb
def feed(input)
      heads = [@start]
      
      # Move any initial e-transitions
      if has_transition?(@start, '&')
        transition(@start, '&').each { |h| heads << h } 
      end
      
      # Iterate through each symbol of input string
      input.each_char do |symbol|
        newHeads, eTrans = [], []
                
        heads.each do |head|
          # Check if head can transition read symbol
          # Head dies if no transition for symbol
          if has_transition?(head, symbol)
            transition(head, symbol).each { |t| newHeads << t }
          end
        end
        
        # Move any e-transitions
        newHeads.each do |head|
          if has_transition?(head, '&')
            transition(head, '&').each { |t| eTrans << t }
          end
        end
        eTrans.each { |t| newHeads << t }
        
        heads = newHeads
        break if heads.empty?
      end
      
      accept = false
      heads.each { |head| accept = true if accept_state? head }

      resp = {
        input: input,
        accept: accept,
        heads: heads
      }
    end
def feed(input)
      heads = [@start]
      
      # Move any initial e-transitions
      if has_transition?(@start, '&')
        transition(@start, '&').each { |h| heads << h } 
      end
      
      # Iterate through each symbol of input string
      input.each_char do |symbol|
        newHeads, eTrans = [], []
                
        heads.each do |head|
          # Check if head can transition read symbol
          # Head dies if no transition for symbol
          if has_transition?(head, symbol)
            transition(head, symbol).each { |t| newHeads << t }
          end
        end
        
        # Move any e-transitions
        newHeads.each do |head|
          if has_transition?(head, '&')
            transition(head, '&').each { |t| eTrans << t }
          end
        end
        eTrans.each { |t| newHeads << t }
        
        heads = newHeads
        break if heads.empty?
      end
      
      accept = false
      heads.each { |head| accept = true if accept_state? head }

      resp = {
        input: input,
        accept: accept,
        heads: heads
      }
    end
def feed ( input ) heads = [ @start ] # Move any initial e-transitions if has_transition? ( @start , '&' ) transition ( @start , '&' ) . each { | h | heads << h } end # Iterate through each symbol of input string input . each_char do | symbol | newHeads , eTrans = [ ] , [ ] heads . each do | head | # Check if head can transition read symbol # Head dies if no transition for symbol if has_transition? ( head , symbol ) transition ( head , symbol ) . each { | t | newHeads << t } end end # Move any e-transitions newHeads . each do | head | if has_transition? ( head , '&' ) transition ( head , '&' ) . each { | t | eTrans << t } end end eTrans . each { | t | newHeads << t } heads = newHeads break if heads . empty? end accept = false heads . each { | head | accept = true if accept_state? head } resp = { input : input , accept : accept , heads : heads } end
@todo Check that each state is connected.
   Iterate through each states to verify the graph
   is not disjoint.
 Runs the input on the machine and returns a Hash describing
 the machine's final state after running.

 @param [String] input the string to use as input for the NFA
 @return [Hash] a hash describing the NFA state after running
   * :input [String] the original input string
   * :accept [Boolean] whether or not the NFA accepted the string
   * :heads [Array] the state which the head is currently on
@todo Check that each state is connected . Iterate through each states to verify the graph is not disjoint . Runs the input on the machine and returns a Hash describing the machine s final state after running .