Created
May 20, 2011 00:53
-
-
Save rufo/982120 to your computer and use it in GitHub Desktop.
Rochester.rb LCD Number Solution
This file contains 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 | |
@numbers = [ | |
["-", "|", "|", " ", "|", "|", "-"], | |
[" ", " ", "|", " ", " ", "|", " "], | |
["-", " ", "|", "-", "|", " ", "-"], | |
["-", " ", "|", "-", " ", "|", "-"], | |
[" ", "|", "|", "-", " ", "|", " "], | |
["-", "|", " ", "-", " ", "|", "-"], | |
["-", "|", " ", "-", "|", "|", "-"], | |
["-", " ", "|", " ", " ", "|", " "], | |
["-", "|", "|", "-", "|", "|", "-"], | |
["-", "|", "|", "-", " ", "|", "-"] | |
] | |
def number_to_lcd(i, size = 2) | |
n = @numbers[i.to_i] | |
rows = [] | |
rows[0] = " " + (n[0] * size) + " " | |
size.times do | |
rows << n[1] + (" " * size) + n[2] | |
end | |
rows << " " + (n[3] * size) + " " | |
size.times do | |
rows << n[4] + (" " * size) + n[5] | |
end | |
rows << " " + (n[6] * size) + " " | |
end | |
rows = [] | |
size = 2 | |
input = ARGV[0] | |
if ARGV[0] == "-s" | |
size = ARGV[1].to_i | |
input = ARGV[2] | |
end | |
input.chomp.split("").each do |char| | |
number_to_lcd(char, size).each_with_index do |num_row, i| | |
rows[i] ||= [] | |
rows[i] << num_row | |
end | |
end | |
puts rows.map{|r| r.join(" ")} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment