Created
December 22, 2010 22:19
-
-
Save mzp/752189 to your computer and use it in GitHub Desktop.
SendMoreMoney.scala
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
| object SendMoreMoney { | |
| def int(xs : Int*) : Int = | |
| xs.foldLeft(0)( _ * 10 + _) | |
| def solve : Seq[(Int, Int,Int)] = { | |
| val digits = 0 to 9 | |
| for { | |
| s <- digits | |
| e <- digits diff List(s) | |
| n <- digits diff List(s, e) | |
| d <- digits diff List(s, e, n) | |
| m <- digits diff List(s, e, n, d) | |
| o <- digits diff List(s, e, n, d, m) | |
| r <- digits diff List(s, e, n, d, m, o) | |
| y <- digits diff List(s, e, n, d, m, o, r) | |
| if s != 0 && m != 0 && int(s, e, n, d) + int(m, o, r, e) == int(m, o, n, e, y) | |
| } yield (int(s, e, n, d) , int(m, o, r, e) , int(m, o, n, e, y)) | |
| } | |
| def main(args : Array[String]) { | |
| println(solve) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update