Created
April 9, 2016 12:24
-
-
Save NigoroJr/41ff5860ece6d0b7de76b84848fed57e to your computer and use it in GitHub Desktop.
Displays 7-segment digits
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
| #!/usr/bin/env ruby | |
| # Example usage: | |
| # $ cat <<EOS | this_script | |
| # 16:47 | |
| # 23:59 | |
| # 00:08 | |
| # end | |
| # EOS | |
| # | |
| # https://open.kattis.com/problems/display | |
| digits = { | |
| 1 => <<-EOS, | |
| + | |
| | | |
| | | |
| + | |
| | | |
| | | |
| + | |
| EOS | |
| 2 => <<-EOS, | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| EOS | |
| 3 => <<-EOS, | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| EOS | |
| 4 => <<-EOS, | |
| + + | |
| | | | |
| | | | |
| +---+ | |
| | | |
| | | |
| + | |
| EOS | |
| 5 => <<-EOS, | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| EOS | |
| 6 => <<-EOS, | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| | | | |
| | | | |
| +---+ | |
| EOS | |
| 7 => <<-EOS, | |
| +---+ | |
| | | |
| | | |
| + | |
| | | |
| | | |
| + | |
| EOS | |
| 8 => <<-EOS, | |
| +---+ | |
| | | | |
| | | | |
| +---+ | |
| | | | |
| | | | |
| +---+ | |
| EOS | |
| 9 => <<-EOS, | |
| +---+ | |
| | | | |
| | | | |
| +---+ | |
| | | |
| | | |
| +---+ | |
| EOS | |
| 0 => <<-EOS, | |
| +---+ | |
| | | | |
| | | | |
| + + | |
| | | | |
| | | | |
| +---+ | |
| EOS | |
| -1 => <<-EOS, | |
| o | |
| o | |
| EOS | |
| } | |
| times = STDIN.readlines.map(&:chomp).select do |l| | |
| l != 'end' | |
| end | |
| times.each do |t| | |
| chars = t.split('') | |
| chars[chars.index(':')] = '-1' | |
| chars.map!(&:to_i) | |
| first, *rest = chars | |
| rest = rest.map { |key| digits[key].split("\n") } | |
| digits[first].split("\n").zip(*rest) do |digs| | |
| puts digs.join(' ') | |
| end | |
| puts | |
| puts | |
| end | |
| puts 'end' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment