ScalaでProject Euler(92)

Problem 59

シャーロックホームズに出てきたようにeが一番多いのだろうと思ったら違いました。

def max_count(chars :Array[Int], l :Int) :Int = {
    val a = new Array[Int](128)
    for(k <- l until chars.size by 3) a(chars(k)) += 1
    println (a.toList)
    (0 to 127).map(n => (a(n), n)).max._2
}

val s = io.Source.fromFile("cipher1.txt")
val chars = s.getLines.next.split(',').map(x => x.toInt)
val keys = Array.range(0, 3).map(l => max_count(chars, l) ^ (' '.toInt))
println ((0 to chars.size - 1).map(k => chars(k) ^ keys(k % 3)).sum)