deterministic finite automata in ruby