Created
October 2, 2015 18:14
-
-
Save theraphim/53740f58951b1476ee93 to your computer and use it in GitHub Desktop.
I have no idea what this is.
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 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