Created
January 20, 2014 23:08
-
-
Save detournemint/8531239 to your computer and use it in GitHub Desktop.
LCD ruby quiz 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
def lcd(num, size) | |
horizontal = Proc.new do |n| | |
a = [] | |
a << " " | |
a << ("-" * n) | |
a << " " | |
end | |
vertical = Proc.new do |n| | |
a = [] | |
a << "|" | |
a << (" " * n) | |
a << "|" | |
end | |
n = num.to_s.split(//) | |
n.each do |num| | |
num = num.to_i | |
if num == 1 || num == 4 | |
top = Proc.new do |n| | |
a = [] | |
a << " " | |
a << (" " * n) | |
a << " " | |
end | |
else | |
top = horizontal | |
end | |
if num == 1 || num == 2 || num == 3 || num == 7 | |
mid1 = Proc.new do |n| | |
a = [] | |
a << " " | |
a << (" " * n) | |
a << "|" | |
end | |
elsif num == 5 || num == 6 | |
mid1 = Proc.new do |n| | |
a = [] | |
a << "|" | |
a << (" " * n) | |
a << " " | |
end | |
else | |
mid1 = vertical | |
end | |
if num == 1 || num == 7 | |
mid2 = Proc.new do |n| | |
a = [] | |
a << " " | |
a << (" " * n) | |
a << " " | |
end | |
else | |
mid2 = horizontal | |
end | |
if num == 2 || num == 6 | |
mid3 = Proc.new do |n| | |
a = [] | |
a << "|" | |
a << (" " * n) | |
a << " " | |
end | |
elsif num == 3 || num == 4 || num == 5 || num == 9 || num == 7 || num == 1 | |
mid3 = Proc.new do |n| | |
a = [] | |
a << " " | |
a << (" " * n) | |
a << "|" | |
end | |
else | |
mid3 = vertical | |
end | |
if num == 1 || num == 4 || num == 7 || num == 9 | |
bottom = Proc.new do |n| | |
a = [] | |
a << " " | |
a << (" " * n) | |
a << " " | |
end | |
else | |
bottom = horizontal | |
end | |
puts top.call(size) | |
puts mid1.call(size).join | |
puts mid2.call(size) | |
puts mid3.call(size).join | |
puts bottom.call(size) | |
end | |
end | |
lcd(55,5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment