Skip to content

Instantly share code, notes, and snippets.

@mzp
Created December 22, 2010 22:19
Show Gist options
  • Select an option

  • Save mzp/752189 to your computer and use it in GitHub Desktop.

Select an option

Save mzp/752189 to your computer and use it in GitHub Desktop.
SendMoreMoney.scala
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)
}
}
@mzp
Copy link
Copy Markdown
Author

mzp commented Dec 22, 2010

update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment