The old Google Groups will be going away soon, but your browser is incompatible with the new version.
KataRomanNumerals
 There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic. There was an error processing your request. Please try again. Standard view   View as tree
 1 message

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Aug 12 2010, 8:11 pm
From: "<peter.lewe...@swipnet.se>" <peter.lewe...@swipnet.se>
Date: Fri, 13 Aug 2010 02:11:57 +0200
Local: Thurs, Aug 12 2010 8:11 pm
Subject: KataRomanNumerals

> Någon som var med och/eller har löst denna Kata i scala, har ni lust
> att dela med er av er lösning, jag skulle vilja jämföra och få lite
> idéer.

Något i den här stilen kanske:

object RomanNumeral {
val r = "IVXLCDM.".iterator.sliding(3, 2).withPartial(true).toArray

def conv(t: (Char, Int)) = {
val s = r(t._2)

t._1 match {
case '9' => s(0).toString + s(2)
case '4' => s take 2 mkString
case c   => {
val n = c.toString.toInt
(if (n >= 5) s(1) else "") + s(0).toString * (n % 5)
}
}
}

def apply(n: Int) = {
require(n <= 3999)

((n.toString.reverse zipWithIndex) reverse) map conv mkString
}
}