Created
February 20, 2013 14:47
-
-
Save zerosum/4996023 to your computer and use it in GitHub Desktop.
Project Euler: Problem 89
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
| package euler.zerosum | |
| import io.Source | |
| object Euler0089 { | |
| def main(args: Array[String]) { | |
| val f = Source.fromFile("resources/roman.txt") | |
| val roman = f.getLines.toList | |
| f.close() | |
| println(roman.mkString.length - roman.map(minimalize(_)).mkString.length) | |
| } | |
| private def minimalize(roman: String): String = { | |
| // DCCCC -> CM | |
| // CCCC -> CD | |
| // LXXXX -> XC | |
| // XXXX -> XL | |
| // VIIII -> IX | |
| // IIII -> IV | |
| // minimalize後の文字数だけわかればよい。いずれも2文字に変換される | |
| roman.replaceAll("DCCCC|CCCC|LXXXX|XXXX|VIIII|IIII", "**") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment