Skip to content

raglub/nonograms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nonograms

Solve the puzzle game nonograms.

Installation

Add this line to your application's Gemfile:

gem 'nonograms'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nonograms

Usage

For example:

          2           1
      1   1   1       1
    +---+---+---+---+---+
  1 |   |   |   |   |   |
    +---+---+---+---+---+
2 1 |   |   |   |   |   |
    +---+---+---+---+---+
  1 |   |   |   |   |   |
    +---+---+---+---+---+
1 1 |   |   |   |   |   |
    +---+---+---+---+---+

We should get result

          2           1
      1   1   1       1
    +---+---+---+---+---+
  1 |   | # |   |   |   |
    +---+---+---+---+---+
2 1 |   | # | # |   | # |
    +---+---+---+---+---+
  1 | # |   |   |   |   |
    +---+---+---+---+---+
1 1 |   | # |   |   | # |
    +---+---+---+---+---+

in line result should be "01000"+"01101"+"10000"+"01001"

You can solve this example when you write the code below

> require "nonograms"

> vertical = [[1], [2, 1], [1], [], [1, 1]]
> horizontal = [[1], [2, 1], [1], [1, 1]]
> @nonograms = Nonograms.new(horizontal, vertical)
> @nonograms.solve #=> ["01000"+"01101"+"10000"+"01001", ...]

Check whether entered data are properly

> @nonograms.properly_data_entered? #=> true

Display result on the console

> @nonograms.display

#=> result: 0
#=>      1 2 1   1
#=>        1     1
#=>      ----------
#=> 1   |  ■
#=> 2 1 |  ■ ■   ■
#=> 1   |■
#=> 1 1 |  ■     ■

#=> result: 1
#=>      1 2 1   1
#=>        1     1
#=>      ----------
#=> 1   |  ■
#=> 2 1 |■ ■     ■
#=> 1   |    ■
#=> 1 1 |  ■     ■

About

Solve the puzzle game nonograms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages