Fix romans module
This commit is contained in:
parent
a8c3c2ef0d
commit
c433ae1aaa
1 changed files with 3 additions and 6 deletions
|
|
@ -44,16 +44,13 @@ proc decimalToRoman*(number: range[1..3_999]): string =
|
||||||
("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9),
|
("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9),
|
||||||
("V", 5), ("IV", 4), ("I", 1)]
|
("V", 5), ("IV", 4), ("I", 1)]
|
||||||
result = ""
|
result = ""
|
||||||
var decVal = number
|
var decVal: int = number
|
||||||
for key, val in items(romanComposites):
|
for key, val in items(romanComposites):
|
||||||
while decVal >= val:
|
while decVal >= val:
|
||||||
dec(decVal, val)
|
dec(decVal, val)
|
||||||
result.add(key)
|
result.add(key)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import math
|
for i in 1 .. 3_999:
|
||||||
randomize()
|
assert i == i.decimalToRoman.romanToDecimal
|
||||||
for i in 1 .. 100:
|
|
||||||
var rnd = 1 + random(3990)
|
|
||||||
assert rnd == rnd.decimalToRoman.romanToDecimal
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue