combinatorial_puzzle_solver 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +30 -7
- data/Rakefile +20 -20
- data/combinatorial_puzzle_solver.gemspec +1 -1
- data/example_puzzles/compile_examples.rb +3 -2
- data/example_puzzles/examples.yaml +5 -5
- data/lib/combinatorial_puzzle_solver/version.rb +1 -1
- metadata +20 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c97ab26d922c738ae675bbc88cb26d8b8d259d5
|
4
|
+
data.tar.gz: f2cf755474ec48ee6b028795e243619fef637976
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 616483c367ca49dfbbea46f862dcda1bdfae2b5f07eaf3dacab3cacaffa0e87f5dd6054745d2bd6d019999010176335a4c9269660b80718cf385019cfdc8a0bf
|
7
|
+
data.tar.gz: bb60d2804922912522d8622e1feee0124030754c8a68ba0ed4125cd972806f290511d51e3eb6d042efda925e691dce3ca0aa4e9a6650dd72b189b1dd002d300c
|
data/README.md
CHANGED
@@ -20,15 +20,33 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage for `solve_sudoku`
|
22
22
|
|
23
|
-
The program `solve_sudoku` reads sudoku puzzles from files
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
The program `solve_sudoku` reads sudoku puzzles from files
|
24
|
+
(or stdin, if no filenames is given) and solves them by
|
25
|
+
constraint resolution. If constraint resolution is not enough
|
26
|
+
to solve the puzzle, it will resort to a trial and error
|
27
|
+
approach. The exit code will indicate if all parsed puzzles
|
28
|
+
were completely solved or not.
|
29
|
+
|
30
|
+
Each resolution step and the current state of the puzzle can
|
31
|
+
be written to stdout for diagnostic purposes. It is also
|
32
|
+
possible to abort after a given number of steps if a complete
|
33
|
+
resolution is not desired, which would be the case if you only
|
34
|
+
want a couple of clues.
|
35
|
+
|
36
|
+
Note that the step output and abort functionality is not
|
37
|
+
available when the puzzle is solved by trial and error.
|
38
|
+
|
39
|
+
The default behavior is resolve all given puzzles (with trial
|
40
|
+
and error, if neccessary) and indicate by exit status whether
|
41
|
+
all puzzles where completely resolved. No output is given
|
42
|
+
unless explicitly asked for.
|
27
43
|
|
28
44
|
|
29
45
|
###Printing the parsed puzzles, `-i`.
|
30
46
|
|
31
|
-
The parser will interpret digits (0-9) as values in the puzzle
|
47
|
+
The parser will interpret digits (0-9) as values in the puzzle
|
48
|
+
and disregard anything else. The option `-i` will output the
|
49
|
+
parsed puzzle before it solves it.
|
32
50
|
|
33
51
|
Given the file `example_puzzles/simple`:
|
34
52
|
|
@@ -333,7 +351,9 @@ Invoking `solve_sudoku example_puzzles/4x4 --4x4 -p` will return exit code `0` a
|
|
333
351
|
|
334
352
|
###Use constraint resolution only, `-r`.
|
335
353
|
|
336
|
-
You can avoid the trial and error functionality. Note though that this might not
|
354
|
+
You can avoid the trial and error functionality. Note though that this might not
|
355
|
+
lead to a completely solved puzzle, which would imply a failure return code.
|
356
|
+
|
337
357
|
The input and incomplete result is demonstrated below.
|
338
358
|
|
339
359
|
Given the file `example_puzzles/medium`:
|
@@ -427,7 +447,9 @@ Invoking `solve_sudoku example_puzzles/hard -i -o -r` will return exit code `256
|
|
427
447
|
|
428
448
|
###Abort after a given number of steps, `-c NUM`, `--clues NUM`.
|
429
449
|
|
430
|
-
If you don't want the entire puzzle solved, but just a couple of clues on
|
450
|
+
If you don't want the entire puzzle solved, but just a couple of clues on
|
451
|
+
how to get forward, you can abort the resolution with `-c`, and print each
|
452
|
+
step with `-s`.
|
431
453
|
|
432
454
|
Given the file `example_puzzles/simple`:
|
433
455
|
|
@@ -450,6 +472,7 @@ Invoking `solve_sudoku example_puzzles/simple -s -c 3` will return exit code `0`
|
|
450
472
|
|
451
473
|
|
452
474
|
|
475
|
+
|
453
476
|
## Development
|
454
477
|
|
455
478
|
After checking out the repo, run `bin/setup` to install dependencies.
|
data/Rakefile
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
Bundler.setup
|
3
3
|
|
4
|
-
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'yard'
|
6
|
+
require 'rspec/illustrate/yard'
|
5
7
|
require "rspec/core/rake_task"
|
6
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
7
|
-
t.rspec_opts = "--format RSpec::Formatters::IllustratedDocumentationFormatter"
|
8
|
-
end
|
9
8
|
|
10
|
-
desc "Execute
|
11
|
-
|
12
|
-
RSpec::Core::RakeTask.new(:html_spec) do |t|
|
13
|
-
t.rspec_opts = "--format RSpec::Formatters::IllustratedHtmlFormatter --out ./doc/rspec-results.html"
|
14
|
-
end
|
9
|
+
desc "Execute tests"
|
10
|
+
RSpec::Core::RakeTask.new(:test)
|
15
11
|
|
16
|
-
desc "
|
17
|
-
|
18
|
-
|
19
|
-
t.files = ['lib/**/*.rb', '-', 'doc/rspec-results.html', 'doc/examples.md' ]
|
12
|
+
desc "Execute RSpec and create a test report at ./doc/api.rspec."
|
13
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
14
|
+
t.rspec_opts = "--format RSpec::Formatters::YARD --out ./doc/api.rspec"
|
20
15
|
end
|
21
|
-
task :doc => [:html_spec, :examples]
|
22
16
|
|
23
|
-
desc "
|
24
|
-
YARD::Rake::YardocTask.new(:
|
25
|
-
t.
|
17
|
+
desc "Create documentation."
|
18
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
19
|
+
t.files = ['lib/**/*.rb', 'doc/api.rspec', '-', 'doc/api.rspec', 'doc/examples.md' ]
|
26
20
|
end
|
21
|
+
task :doc => [:spec, :examples]
|
22
|
+
CLEAN.include("doc")
|
23
|
+
CLEAN.include(".yardoc")
|
27
24
|
|
28
|
-
|
25
|
+
desc "Create example documentation."
|
29
26
|
require_relative 'example_puzzles/compile_examples'
|
30
27
|
task :examples => ['doc/examples.md']
|
31
28
|
file 'doc/examples.md' => FileList["example_puzzles/*"] do
|
32
|
-
markdown = compile_examples_to_markdown(Dir.glob('example_puzzles/*.yaml'))
|
29
|
+
markdown = compile_examples_to_markdown(Dir.glob('example_puzzles/*.yaml'),2)
|
33
30
|
File.write('doc/examples.md', markdown)
|
34
31
|
$stderr.puts "examples ok!"
|
35
32
|
end
|
36
33
|
|
34
|
+
desc "List the undocumented code."
|
35
|
+
YARD::Rake::YardocTask.new(:list_undoc) do |t|
|
36
|
+
t.stats_options = ['--list-undoc']
|
37
|
+
end
|
37
38
|
|
38
|
-
task :test => [:spec, :examples]
|
39
39
|
task :default => :doc
|
40
40
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.8"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_development_dependency "rspec-illustrate", "~> 0.
|
26
|
+
spec.add_development_dependency "rspec-illustrate", "~> 0.2.0"
|
27
27
|
|
28
28
|
spec.add_development_dependency "yard", "~> 0.8.7.6"
|
29
29
|
spec.add_development_dependency "redcarpet", "~> 3.2.2"
|
@@ -6,9 +6,10 @@ require 'open3'
|
|
6
6
|
# it into a markdown doucument.
|
7
7
|
#
|
8
8
|
# @param yaml_files [Array<String>] the yaml files to parse
|
9
|
+
# @param level [Fixnum] the initial subsection level
|
9
10
|
# @return [String] the compiled markdown document.
|
10
|
-
def compile_examples_to_markdown(yaml_files)
|
11
|
-
compile(yaml_files.collect{|yaml_file| YAML.load_file(yaml_file)})
|
11
|
+
def compile_examples_to_markdown(yaml_files, level)
|
12
|
+
compile(yaml_files.collect{|yaml_file| YAML.load_file(yaml_file)}, level)
|
12
13
|
end
|
13
14
|
|
14
15
|
# Compiles a given node of the YAML tree into markdown.
|
@@ -1,13 +1,13 @@
|
|
1
1
|
---
|
2
2
|
:section: Sudoku Solver
|
3
3
|
:content:
|
4
|
-
- :comment:
|
4
|
+
- :comment: |
|
5
5
|
The program `solve_sudoku` reads sudoku puzzles from files
|
6
6
|
(or stdin, if no filenames is given) and solves them by
|
7
7
|
constraint resolution. If constraint resolution is not enough
|
8
8
|
to solve the puzzle, it will resort to a trial and error
|
9
9
|
approach. The exit code will indicate if all parsed puzzles
|
10
|
-
|
10
|
+
were completely solved or not.
|
11
11
|
|
12
12
|
Each resolution step and the current state of the puzzle can
|
13
13
|
be written to stdout for diagnostic purposes. It is also
|
@@ -24,7 +24,7 @@
|
|
24
24
|
unless explicitly asked for.
|
25
25
|
|
26
26
|
- :example: Printing the parsed puzzles, `-i`.
|
27
|
-
:comment:
|
27
|
+
:comment: |
|
28
28
|
The parser will interpret digits (0-9) as values in the puzzle
|
29
29
|
and disregard anything else. The option `-i` will output the
|
30
30
|
parsed puzzle before it solves it.
|
@@ -186,7 +186,7 @@
|
|
186
186
|
2\n---+---\n4 2|1 3\n3 1|2 4\n\n2 3|4 1\n1 4|3 2\n---+---\n4 2|1 3\n3 1|2 4\n\n"
|
187
187
|
|
188
188
|
- :example: Use constraint resolution only, `-r`.
|
189
|
-
:comment:
|
189
|
+
:comment: |
|
190
190
|
You can avoid the trial and error functionality. Note though that this might not
|
191
191
|
lead to a completely solved puzzle, which would imply a failure return code.
|
192
192
|
|
@@ -227,7 +227,7 @@
|
|
227
227
|
|
228
228
|
|
229
229
|
- :example: Abort after a given number of steps, `-c NUM`, `--clues NUM`.
|
230
|
-
:comment:
|
230
|
+
:comment: |
|
231
231
|
If you don't want the entire puzzle solved, but just a couple of clues on
|
232
232
|
how to get forward, you can abort the resolution with `-c`, and print each
|
233
233
|
step with `-s`.
|
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combinatorial_puzzle_solver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Erik Schlyter
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2015-
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.8'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.8'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '10.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '10.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec-illustrate
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
47
|
+
version: 0.2.0
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
54
|
+
version: 0.2.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: yard
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 0.8.7.6
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 0.8.7.6
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: redcarpet
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- - ~>
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 3.2.2
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- - ~>
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 3.2.2
|
94
83
|
description: A resolver of combinatorial number-placement puzzles, like Sudoku.
|
@@ -99,7 +88,7 @@ executables:
|
|
99
88
|
extensions: []
|
100
89
|
extra_rdoc_files: []
|
101
90
|
files:
|
102
|
-
- .gitignore
|
91
|
+
- ".gitignore"
|
103
92
|
- Gemfile
|
104
93
|
- LICENSE.txt
|
105
94
|
- README.md
|
@@ -125,30 +114,26 @@ files:
|
|
125
114
|
homepage: https://github.com/ErikSchlyter/combinatorial_puzzle_solver
|
126
115
|
licenses:
|
127
116
|
- MIT
|
117
|
+
metadata: {}
|
128
118
|
post_install_message:
|
129
119
|
rdoc_options: []
|
130
120
|
require_paths:
|
131
121
|
- lib
|
132
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
123
|
requirements:
|
135
|
-
- -
|
124
|
+
- - ">="
|
136
125
|
- !ruby/object:Gem::Version
|
137
126
|
version: 1.9.3
|
138
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
128
|
requirements:
|
141
|
-
- -
|
129
|
+
- - ">="
|
142
130
|
- !ruby/object:Gem::Version
|
143
131
|
version: '0'
|
144
|
-
segments:
|
145
|
-
- 0
|
146
|
-
hash: 2443890313582530978
|
147
132
|
requirements: []
|
148
133
|
rubyforge_project:
|
149
|
-
rubygems_version:
|
134
|
+
rubygems_version: 2.2.2
|
150
135
|
signing_key:
|
151
|
-
specification_version:
|
136
|
+
specification_version: 4
|
152
137
|
summary: A resolver of combinatorial number-placement puzzles, like Sudoku.
|
153
138
|
test_files: []
|
154
139
|
has_rdoc:
|