Last active
February 21, 2022 21:07
-
-
Save kumo/a8e1cb1f4b7cff1548c7 to your computer and use it in GitHub Desktop.
Revisions
-
kumo revised this gist
Jul 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ func toRoman(number: Int) -> String { if (div > 0) { for j in 0..<div { //println("Should add \(romanChar) to string") romanValue += romanChar -
kumo renamed this gist
Jun 18, 2014 . 1 changed file with 3 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import Foundation func toRoman(number: Int) -> String { let romanValues = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] @@ -23,15 +21,13 @@ func toRoman(number: Int) -> String { { //println("Should add \(romanChar) to string") romanValue += romanChar } startingValue -= arabicValue * div } } return romanValue } toRoman(2014) -
kumo created this gist
Jun 18, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ // Playground - noun: a place where people can play import Foundation var arabicNumber = 2105 func toRoman(number: Int) -> String { let romanValues = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] let arabicValues = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] var romanValue = "" var startingValue = number for (index, romanChar) in enumerate(romanValues) { var arabicValue = arabicValues[index] var div = startingValue / arabicValue if (div > 0) { for j in 0..div { //println("Should add \(romanChar) to string") romanValue += romanChar startingValue -= arabicValue } } } return romanValue } toRoman(2105) toRoman(301)