tracks/nim/exercises/roman-numerals/example.nim in trackler-2.2.1.172 vs tracks/nim/exercises/roman-numerals/example.nim in trackler-2.2.1.173
- old
+ new
@@ -1,30 +1,29 @@
type
- Numeral = tuple[number: int, roman: string]
- NumeralArray = array[13, Numeral]
+ Numeral = tuple[number: int, roman: string]
+ NumeralArray = array[13, Numeral]
let
- numeral_mapping: NumeralArray = [
- (1000, "M"),
- (900, "CM"),
- (500, "D"),
- (400, "CD"),
- (100, "C"),
- (90, "XC"),
- (50, "L"),
- (40, "XL"),
- (10, "X"),
- (9, "IX"),
- (5, "V"),
- (4, "IV"),
- (1, "I")
- ]
+ numeral_mapping: NumeralArray = [
+ (1000, "M"),
+ (900, "CM"),
+ (500, "D"),
+ (400, "CD"),
+ (100, "C"),
+ (90, "XC"),
+ (50, "L"),
+ (40, "XL"),
+ (10, "X"),
+ (9, "IX"),
+ (5, "V"),
+ (4, "IV"),
+ (1, "I")
+ ]
-proc numeral*(number: int): string =
- var s = ""
- var n = number
- for numeral in numeral_mapping:
- while n >= numeral.number:
- s = s & numeral.roman
- n = n - numeral.number
- return s
+proc roman*(number: int): string =
+ result = ""
+ var n = number
+ for numeral in numeral_mapping:
+ while n >= numeral.number:
+ result = result & numeral.roman
+ n = n - numeral.number
\ No newline at end of file