Created
January 31, 2016 21:48
-
-
Save stanch/206400447f97971d78dc 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
val l2d = Map('i' -> 1, 'v' -> 5, 'x' -> 10, 'l' -> 50, 'c' -> 100) | |
def compute(ds: Seq[Int]) = ds.foldRight((0, 0)) { | |
case (d, (acc, last)) => if (d < last) (acc - d, last) else (acc + d, d) | |
} | |
def roman(numeral: String) = compute(numeral map l2d)._1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment