Last active
October 12, 2016 20:16
-
-
Save dockimbel/1abde8f2dfaf75816384609edf59098f to your computer and use it in GitHub Desktop.
Arabic to Roman numbers converter in Red
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Purpose: "Arabic to Roman numbers converter" | |
Date: "06-Oct-2016" | |
] | |
table: [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] | |
to-Roman: function [n [integer!]] reduce [ | |
'case collect [ | |
foreach [a r] table [ | |
keep compose/deep [n >= (a) [append copy (form r) any [to-Roman n - (a) copy ""]]] | |
] | |
] | |
] | |
print to-Roman 40 | |
print to-Roman 33 | |
print to-Roman 1888 | |
print to-Roman 2016 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment