Skip to content

Instantly share code, notes, and snippets.

@theraphim
Created October 2, 2015 18:14
Show Gist options
  • Save theraphim/53740f58951b1476ee93 to your computer and use it in GitHub Desktop.
Save theraphim/53740f58951b1476ee93 to your computer and use it in GitHub Desktop.
I have no idea what this is.
object A {
def main(args: Array[String]) { println(b(Nil)) }
def b(list: List[Int]):List[List[Int]] = list match {
case full if full.size == 8 => List(full)
case _ => def valid(t:List[Int])(h:Int) = {
def diagonal(op: (Int,Int)=>Int, n:Int, li:List[Int]): Boolean = li match {
case Nil => false
case h :: t => n == h || diagonal(op, op(n,1), t)
}
! (t.contains(h) || diagonal(_+_, h+1, t) || diagonal(_-_, h-1, t))
}
(1 to 8 toList).filter(valid(list)).map(n => b(n :: list)).flatten
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment