Skip to content

Instantly share code, notes, and snippets.

@x17x2a
Created March 4, 2012 17:08
Show Gist options
  • Select an option

  • Save x17x2a/1973923 to your computer and use it in GitHub Desktop.

Select an option

Save x17x2a/1973923 to your computer and use it in GitHub Desktop.
Code crashing Julia
adddame(a::Array{Array{Int}}, dame::Array{Int}) = push(copy(a), dame)
hitsany(dame::Array{Int}, dames::Array{Array{Int}}) = any(map((x) -> hits(dame, x), dames))
hits(a::Array{Int}, b::Array{Int}) = any(a == b) || abs(a-b)[1] == abs(a-b)[2]
function solve(x::Int, y::Int, n::Int, d::Array{Array{Int}})
if n == 0
return d
end
for px = 1:x
for py = 1:y
if !hitsany([px, py], d)
s = solve(x, y, n-1, adddame(d, [px, py]))
if s != None
return s
end
end
end
end
None
end
solve(x, y, n) = solve(x, y, n, Array(Array{Int}, 0))
for i = 1:10
print("Solve for $i\n")
print(solve(8, 8, i))
print("\n")
end
@ViralBShah
Copy link

This would make a nice addition to examples. Can you generate a pull request when ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment