Created
July 27, 2019 19:13
-
-
Save rugyoga/2138bdbd5aff13540315e6054f1f418b to your computer and use it in GitHub Desktop.
Bitmask based solution to N queens
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
def unsafe?(file, rank) | |
get?(@ranks, rank) || | |
get?(@northwests, northwest(file, rank)) || | |
get?(@northeasts, northeast(file, rank)) | |
end | |
def move!(file, rank) | |
super(file, rank) | |
@ranks = set!(@ranks, rank) | |
@northwests = set!(@northwests, northwest(file, rank)) | |
@northeasts = set!(@northeasts, northeast(file, rank)) | |
end | |
def unmove!(file, rank) | |
super(file, rank) | |
@ranks = clear!(@ranks, rank) | |
@northwests = clear!(@northwests, northwest(file, rank)) | |
@northeasts = clear!(@northeasts, northeast(file, rank)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment