add colorizer test

This commit is contained in:
Martin Aeschlimann 2021-02-08 16:33:12 +01:00
parent 50dc6c3c66
commit ebac2cfa10
2 changed files with 2569 additions and 0 deletions

View file

@ -0,0 +1,26 @@
# n-queens (nqueens) solver, for nsquaresx-by-nsquaresy board
struct Queen
x::Int
y::Int
end
hitshorz(queena, queenb) = queena.x == queenb.x
hitsvert(queena, queenb) = queena.y == queenb.y
hitsdiag(queena, queenb) = abs(queena.x - queenb.x) == abs(queena.y - queenb.y)
hitshvd(qa, qb) = hitshorz(qa, qb) || hitsvert(qa, qb) || hitsdiag(qa, qb)
hitsany(testqueen, queens) = any(q -> hitshvd(testqueen, q), queens)
function trysolve(nsquaresx, nsquaresy, nqueens, presqueens = ())
nqueens == 0 && return presqueens
for xsquare in 1:nsquaresx
for ysquare in 1:nsquaresy
testqueen = Queen(xsquare, ysquare)
if !hitsany(testqueen, presqueens)
tryqueens = (presqueens..., testqueen)
maybesol = trysolve(nsquaresx, nsquaresy, nqueens - 1, tryqueens)
maybesol !== nothing && return maybesol
end
end
end
return nothing
end

File diff suppressed because it is too large Load diff