Skip to content

Instantly share code, notes, and snippets.

@rugyoga
Created July 27, 2019 19:05
Show Gist options
  • Save rugyoga/9425bee8ee5e387d3bbfbd39004a3505 to your computer and use it in GitHub Desktop.
Save rugyoga/9425bee8ee5e387d3bbfbd39004a3505 to your computer and use it in GitHub Desktop.
def northwest(file, rank)
file + rank
end
def northeast(file, rank)
file + @size - rank
end
def unsafe?(file, rank)
@queens.any? do |f, r|
r == rank ||
northwest(f, r) == northwest(file, rank) ||
northeast(f, r) == northeast(file, rank)
end
end
def move!(file, rank)
@queens.push([file, rank])
end
def unmove!(_file, _rank)
@queens.pop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment