Skip to content

Instantly share code, notes, and snippets.

@k4200
Created November 11, 2015 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/2f44b9d1599ecb78cd09 to your computer and use it in GitHub Desktop.
Save k4200/2f44b9d1599ecb78cd09 to your computer and use it in GitHub Desktop.
hamamatsu.rb #58 のお題を解いた(Scala)
// http://jukensansu.cocolog-nifty.com/planet/2015/11/post-0b4b.html
// parser combinators とか使えそうな気もするけど分からん
def arrayToDigit(ary: List[Int]): Int = {
ary(0) * 100 + ary(1) * 10 + ary(2)
}
def calcSum(ary: List[Int]): Int = {
List(ary.slice(0, 3), ary.slice(2, 5), ary.slice(4, 7), ary.slice(6, 8) :+ ary(0)).map(arrayToDigit).sum
}
(1 to 8).toList.permutations.filter(ary => calcSum(ary) == 1725).take(1).foreach { l =>
println(s"${l(1)}, ${l(3)}, ${l(5)}, ${l(7)}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment