Created
August 25, 2016 08:23
-
-
Save fujidig/b0cf3d5cf954141fa669f7dd66f7377c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = <<EOS | |
| 0 _ _ R 0 | |
| 0 1 1 R 1 | |
| 1 _ 1 R 2 | |
| 1 1 1 R 1 | |
| 2 _ _ L 3 | |
| 2 1 1 R 2 | |
| 3 _ _ L 3 | |
| 3 1 _ L 4 | |
| 4 _ _ R stop | |
| 4 1 1 L 4 | |
| EOS | |
| b = a.lines.map{|x| | |
| m = x.match(/(\S+) +(\S+) +(\S+) +(\S+) +(\S+)/) | |
| m.to_a[1..-1] | |
| } | |
| states = (b.map{|x| x[0] } + b.map{|x| x[4] }).uniq | |
| puts "digraph sample {" | |
| puts "graph [rankdir = LR];" | |
| states.each do |s| | |
| puts "_#{s} [label=\"#{s}\"];" | |
| end | |
| b.each do |m| | |
| q1, s1, s2, ac, q2 = m | |
| puts "_#{q1} -> _#{q2} [label = \"#{s1} #{s2} #{ac}\"];" | |
| end | |
| puts "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment