-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroman_new.rb
55 lines (37 loc) · 806 Bytes
/
roman_new.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def roman num
while num > 10000 || num <= 0
puts 'Es sollte eine ganze Zahl zwischen 1 und 10000 sein'
num = gets.chomp.to_i
end
puts 'In modernen römischen Zahlen sieht diese Zahl so aus:'
m = 'M' * (num/1000)
d = 'D' * ((num%1000)/500)
c = 'C' * ((num%500)/100)
l = 'L' * ((num%100)/50)
x = 'X' * ((num%50)/10)
v = 'V' * ((num%10)/5)
i = 'I' * (num%5)
# ersetze 'IIII' durch 'IV'
if c == 'CCCC' && d != 'D'
c = 'CD'
elsif c == 'CCCC'
d ='CM'
c = ''
end
if x == 'XXXX' && l != 'L'
x = 'XL'
elsif x == 'XXXX'
l = 'XC'
x = ''
end
if i == 'IIII' && v != 'V'
i = 'IV'
elsif i == 'IIII'
v = 'IX'
i= ''
end
puts m + d + c + l + x + v + i
end
puts 'Bitte gebe eine (ganze) Zahl zwischen eins und Zehntausend ein'
num = gets.chomp.to_i
roman num