2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -14,7 +14,3 @@ def expand(solutions: Iterator[List[Pos]], size: Int, row: Int) =
pos <- rowSet(size, row)
if solution forall (_ legal pos)
} yield pos :: solution
def seed(size: Int) = rowSet(size, 0) map (sol => List(sol))
def solve(size: Int) = (1 until size).foldLeft(seed(size)) (expand(_, size, _))

View file

@ -0,0 +1,18 @@
def vecOk(v: IndexedSeq[Int])(f: (Int,Int) => Int): Boolean = {
def vecOkIter(level: Int)(lst: List[Int]): Boolean = {
if (level > -1) {
val d = f(v(level),level)
if (lst.contains(d)) false
else vecOkIter(level-1)(d :: lst)
}
else true
}
vecOkIter(v.length-1)(List[Int]())
}
def nQueen(n: Int) = for (
v <- (1 to n).permutations
if vecOk(v)(_+_) && vecOk(v)(_-_)
) yield v
nQueen(8)