n_queens
n_queens is a Ruby gem that solves the N-Queens problem using the repository's
existing solver logic (backtracking and bitmask-based methods), wrapped in a clean
public API.
The underlying algorithms in includes/ are preserved as-is.
Installation
Add this line to your application's Gemfile:
gem "n_queens"
Then install:
bundle install
Or install directly:
gem install n_queens
Usage
require "n_queens"
solver = NQueens::Solver.new(8)
result = solver.solve
result.n # => 8
result.count # => 92
result.solutions # => [[0,4,7,5,2,6,1,3], ...]
result.method # => :backtracking
result.duration # => elapsed seconds as Float
Method Dispatch
NQueens::Solver automatically selects the method by board size:
n <= 10: backtracking (:backtracking)11..17: parallel bitmask (:parallel_bitmask)n >= 18: parallel bitmask to file (:parallel_bitmask)
For n >= 18, result.solutions is nil and result.count is read from output
files created by the existing solver path.
Known Counts
The gem includes OEIS A000170 ground-truth counts:
NQueens::KNOWN_COUNTS[1] # => 1
NQueens::KNOWN_COUNTS[4] # => 2
NQueens::KNOWN_COUNTS[8] # => 92
NQueens::KNOWN_COUNTS[12] # => 14200
NQueens::KNOWN_COUNTS[14] # => 365596
Values are included for n = 1..15.
Version
NQueens::VERSION # => "1.0.0"
Development
Run specs:
bundle exec rspec
Build gem:
gem build n_queens.gemspec
License
MIT. See LICENSE.md.