Created
March 4, 2012 17:08
-
-
Save x17x2a/1973923 to your computer and use it in GitHub Desktop.
Code crashing Julia
This file contains hidden or 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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This would make a nice addition to examples. Can you generate a pull request when ready?