Skip to content

Instantly share code, notes, and snippets.

@simonkro
Created December 3, 2012 20:15
Show Gist options
  • Save simonkro/4197669 to your computer and use it in GitHub Desktop.
Save simonkro/4197669 to your computer and use it in GitHub Desktop.
#Maybe it's not the way you would do it in ruby and code is not that
#beautiful and everyone knows how to read file line by line and how to make
#validation of inputs and how to use methods, global and local variables
#but I am sure my idea is genuis. Engoy
class Test
str=ARGV[0]
l = ARGV[0].length
n=Integer(ARGV[0])
#inicializuvaty zminn
table = {"1"=>"I", "5"=>"V", "10"=>"X", "50"=>"L", "100"=>"C", "500"=>"L", "1000"=>"M"}
count = 1
while count <= l
i=l-count
num=Integer(str[i])
k = l-i
if k==1
x = 1 ; y = String"V"; z = String"X" end
if k==2
x = 10; y = String"L"; z = String"C"; end
if k==3
x = 100 ; y = String"D"; z = String"M" end
if k==4
x = 1000; String"O"; z = String"O" end
if num!=0
inum = num*x
delta = inum - 5*x
if (delta < -1*x && delta > -4*x )
c = inum/(1*x)
while c > 0
d = 1*x
roman = table["#{d}"]
puts "#{roman}"
c=c-1
end
end
if (delta > 1*x && delta < 4*x)
c = delta/(1*x)
puts y
while c > 0
d = 1*x
roman = table["#{d}"]
puts "#{roman}"
c=c-1
end
end
if (delta == 1*x)
d = 1*x
roman = table["#{d}"]
puts "#{y}#{roman}"
end
if (delta ==-1*x)
d = 1*x
roman = table["#{d}"]
puts "#{roman}#{y}"
end
if (delta == 0)
puts "#{y}"
end
if (delta >= 4*x)
d = 1*x
roman = table["#{d}"]
puts "#{roman}#{z}"
end
if (delta == -4*x)
d = 1*x
cons = table["#{d}"]
puts "#{cons}"
end
end
count = count + 1
end
puts "Read from the bottom to the top :)). Who needs an easy and obvious way...."
end
class Romanian
table ={"I"=>"1", "V"=>"5", "X"=>"10", "L"=>"50", "C"=>"100", "D"=>"500", "M"=>"1000"}
l=ARGV[0].length
str = ARGV[0]
sum = 0
i = 0
if (l!=1)
while i < l
curr = str[i]
nextt = str[i+1]
arabic_current = Integer(table["#{curr}"])
if (i!=l-1)
arabic_next = Integer(table["#{nextt}"])
else
arabic_next = 0
end
if (arabic_current >= arabic_next)
sum = sum + arabic_current
else
puts "f"
sum = sum - arabic_current
end
i= i + 1
end
else
curr = str[l-1]
arabic_current = Integer(table["#{curr}"])
sum = arabic_current + sum
end
puts "#{str} - > #{sum}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment