-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroman.small
67 lines (61 loc) · 2.33 KB
/
roman.small
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
56
57
58
59
60
61
62
63
64
65
66
67
convert_number_to_roman = (number) =>
convert_number_to_roman_helper(number 1)
convert_number_to_roman_helper = (number place) => {
if (eq(number 0)
() => ""
() => {
digit = modulus(number 10)
right_part = convert_digit_to_roman(digit place)
remaining = floor(divide(number 10))
left_part = convert_number_to_roman_helper(remaining add(place 1))
concat(left_part right_part)
}
)
}
// Converts a single digit to roman numeral
// digit - is a number between 0 - 9
// place - is a number represening what place you are doing
// the conversion for (1 - ones, 2 - tens, 3 - hundreds, 4 - thousands)
convert_digit_to_roman = (digit place) => {
if (eq(digit 0)
() => ""
() =>
if (or(eq(digit 1) or(eq(digit 2) eq(digit 3)))
() => repeat(one(place) digit)
() =>
if (eq(digit 4)
() => concat(one(place) five(place))
() =>
if (eq(digit 5)
() => five(place)
() =>
if (or(eq(digit 6) or(eq(digit 7) eq(digit 8)))
() => concat(five(place) repeat(one(place) subtract(digit 5)))
() =>
if (eq(digit 9)
() => concat(one(place) one(add(place 1)))
() => concat("!" "!")
)
)
)
)
)
)
}
one = (place) => at("IXCMↂ" subtract(place 1))
five = (place) => at("VLDↁ" subtract(place 1))
// print(convert_digit_to_roman(1 1))
// print(convert_digit_to_roman(2 1))
// print(convert_digit_to_roman(3 1))
// print(convert_digit_to_roman(4 1))
// print(convert_digit_to_roman(5 1))
// print(convert_digit_to_roman(6 1))
// print(convert_digit_to_roman(7 1))
// print(convert_digit_to_roman(8 1))
// print(convert_digit_to_roman(9 1))
each(range(1 10001)
(number) => {
roman = convert_number_to_roman(number)
print(concat(number concat(" = " roman)))
}
)