Last active
January 30, 2016 14:05
-
-
Save shrkw/d552a4c02de80ff47591 to your computer and use it in GitHub Desktop.
scalamatsuri 2016
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
/* | |
* MAVE | |
* + RIcK | |
* ------- | |
* Scala | |
*/ | |
import scala.annotation.tailrec | |
@tailrec | |
def combine(v: Traversable[Int], acc: Int = 0): Int = if (v.isEmpty) acc else combine(v.tail, acc * 10 + v.head) | |
def maverick(n: Seq[Int]): Boolean = combine(n.slice(0,4)) + combine(n.slice(4,8)) == combine(List(n(8), n(6), n(1), n(9), n(1))) | |
val l = (0 to 9).permutations.filter(n => | |
n(0) != 0 && | |
n(4) != 0 && | |
n(6) <= 7 && | |
n(8) == 1 && | |
maverick(n) | |
) | |
l.foreach(println) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment