Skip to content

Instantly share code, notes, and snippets.

@simonkro
Created December 3, 2012 20:09
Show Gist options
  • Save simonkro/4197633 to your computer and use it in GitHub Desktop.
Save simonkro/4197633 to your computer and use it in GitHub Desktop.
Roman Numerals
p "Hi, what is your name ?"
@name = gets.chomp
p "Welcome to the quiz, #{@name}! " + "Please enter a Roman numeral with value between 1 and 4 here:"
a = gets.to_i
if a == 1
p "I"
end
if a == 2
p "II"
end
if a == 3
p "III"
end
if a == 4
p "IV"
end
p "OK! Let's do it the other way round ! " +
"Please enter an Arabic numeral with value between I and IV here:" +
"(You may copy paste one of them: I , II , III , IV ) "
b = gets.chomp.to_s
if b == "I"
p 1
end
if b == "II"
p 2
end
if b == "III"
p 3
end
if b == "IV"
p 4
end
p "Well ok, we are done with the first version of this, now copy paste this into your terminal: ruby other_thing.rb"
class Application
def initialize(output)
@output = output
end
def convert
@arabic_array = @output.split(//)
picture = Picture.new(@arabic_array)
picture.change_arabic_to_roman
end
end
class Picture
def initialize(arabic_array)
@roman = {
"1" => "I",
"2" => "II",
"3" => "III",
"4" => "IV",
"5" => "V",
"6" => "VI",
"7" => "VII",
"8" => "VIII",
"9" => "IX",
"0" => "nulla"
}
@arabic_array = arabic_array
end
def change_arabic_to_roman
@roman_array = @arabic_array.map { |c| @roman[c] }
end
end
puts "Type a number between 1 and 3999. You will get the roman number for each of the digits. "
input = gets.chomp
output = Application.new(input)
puts output.convert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment