Last active
January 30, 2016 14:19
-
-
Save modalsoul/d3dd4bb15dcf94d5f18a to your computer and use it in GitHub Desktop.
This file contains 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 Maverick { | |
def main(args:Array[String]) { | |
(0 to 9).permutations.flatMap(Mavericksl(_)).withFilter(_.valid).foreach(println) | |
} | |
case class Mavericksl(m:Int, a:Int, v:Int, e:Int, r:Int, i:Int, c:Int, k:Int, s:Int, l:Int) { | |
override def toString = s"M:$m, A:$a, V:$v, E:$e, R:$r, i:$i, C:$c, K:$k, S:$s, L:$l" | |
val mave = m*1000 + a*100 + v*10 + e | |
val rick = r*1000 + i*100 + c*10 + k | |
val scala = s*10000 + c*1000 + a*101 + l*10 | |
def valid = mave + rick == scala | |
} | |
object Mavericksl { | |
def apply(a:Seq[Int]):Option[Mavericksl] = | |
if(Seq(a(0),a(4),a(8)).forall(_ != 0)) | |
Some(Mavericksl(a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9))) | |
else | |
None | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment