Skip to content

Instantly share code, notes, and snippets.

@stanch
Created January 31, 2016 21:48
Show Gist options
  • Save stanch/206400447f97971d78dc to your computer and use it in GitHub Desktop.
Save stanch/206400447f97971d78dc to your computer and use it in GitHub Desktop.
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