Skip to content

Instantly share code, notes, and snippets.

@shrkw
Last active January 30, 2016 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrkw/d552a4c02de80ff47591 to your computer and use it in GitHub Desktop.
Save shrkw/d552a4c02de80ff47591 to your computer and use it in GitHub Desktop.
scalamatsuri 2016
/*
* 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