Created
June 7, 2016 06:22
-
-
Save kgn/7715a8d2422fbf201fc49c628d1834d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| func romanNumerals(input: Int) -> String { | |
| var number = input | |
| let numerals = ["M", "M", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] | |
| let values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] | |
| var numeralString = "" | |
| for (i, numeral) in numerals.enumerate() { | |
| while number >= values[i] { | |
| number -= values[i] | |
| numeralString += numeral | |
| } | |
| } | |
| return numeralString | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment