sudoku-jedi 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/sudoku_solver.rb +0 -4
- data/lib/sudoku_solver/grid.rb +12 -10
- data/lib/sudoku_solver/point.rb +0 -7
- data/lib/sudoku_solver/version.rb +1 -1
- metadata +2 -11
- data/lib/sudoku_solver/box.rb +0 -16
- data/lib/sudoku_solver/cell.rb +0 -6
- data/lib/sudoku_solver/column.rb +0 -6
- data/lib/sudoku_solver/container.rb +0 -35
- data/lib/sudoku_solver/row.rb +0 -4
- data/spec/box_spec.rb +0 -25
- data/spec/cell_spec.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4a65264e38d3e9e78a2e0cbdf9e433e91efcb25
|
4
|
+
data.tar.gz: 3aed78fd176a87dab990ea30b04e1b0f51392c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b138a51927e75eb17fd5091635c705f6e65e7dd89a974295400836e9772a021af6d25981480b9dabba4cf273049c19dc3e89f28ca19dc1e9555a29ca40757f1
|
7
|
+
data.tar.gz: fb7154e8cf0595d188695d97b9319889a638c92feed36fa4dd6691243a3f60da2246a82f3b24126d2c5a1d3ecd1860942d905f83f69205b395d4ff65c00ff578
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/sudoku-jedi.svg)](http://badge.fury.io/rb/sudoku-jedi)
|
5
5
|
|
6
6
|
Currently solves easy to moderate sudoku puzzles in a flash!
|
7
|
+
This sudoku solver implementation uses solution tactics such as naked pairs, hidden pairs, box/line reduction, and X-wing strategies for tougher puzzles.
|
8
|
+
You can read about these techniques [here](http://www.sudokuwiki.org/sudoku.htm)
|
7
9
|
|
8
10
|
## Installation
|
9
11
|
|
@@ -19,7 +21,7 @@ And then execute:
|
|
19
21
|
|
20
22
|
Or install it yourself as:
|
21
23
|
|
22
|
-
$ gem install
|
24
|
+
$ gem install sudoku-jedi
|
23
25
|
|
24
26
|
## Usage
|
25
27
|
|
data/lib/sudoku_solver.rb
CHANGED
data/lib/sudoku_solver/grid.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative 'box'
|
2
1
|
require_relative 'point'
|
3
2
|
require 'set'
|
4
3
|
|
@@ -12,7 +11,7 @@ class Grid
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
remaining_points.each do |poi|
|
16
15
|
poi.nums = Array(1..9) - (get_box(poi.box) + get_row(poi.y) + get_column(poi.x))
|
17
16
|
end
|
18
17
|
end
|
@@ -191,8 +190,6 @@ class Grid
|
|
191
190
|
|
192
191
|
def hidden_pairs
|
193
192
|
all_naked_pairs
|
194
|
-
# @points.select { |p| p.x == 6 && p.y == 4 }.first.nums = @points.select { |p| p.x == 6 && p.y == 4 }.first.nums - [1,5]
|
195
|
-
# @points.select { |p| p.x == 6 && p.y == 6 }.first.nums = @points.select { |p| p.x == 6 && p.y == 6 }.first.nums - [3,6]
|
196
193
|
|
197
194
|
remaining_points.each do |point|
|
198
195
|
next if point.nums.count <= 1
|
@@ -219,12 +216,17 @@ class Grid
|
|
219
216
|
[:x, :y].each do |symbol|
|
220
217
|
arr = @points.select{ |p| p.nums.include?(num) && p.send(flip(symbol)) == point.send(flip(symbol)) && p.value == 0 }
|
221
218
|
if arr.count == 2 && @points.select { |p| p.value == num && p.send(flip(symbol)) == point.send(flip(symbol)) }.count == 0
|
222
|
-
last = @points.select { |p| p.nums.include?(num) &&
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
219
|
+
last = @points.select { |p| p.nums.include?(num) &&
|
220
|
+
arr.map{ |a| a.send(symbol) }.include?(p.send(symbol)) &&
|
221
|
+
(!arr.include?(p)) &&
|
222
|
+
p.value == 0 && check_row(p.y,p,num,symbol) }
|
223
|
+
if last.all? { |x| x.send(flip(symbol)) == last.first.send(flip(symbol)) } &&
|
224
|
+
last.count == 2 &&
|
225
|
+
@points.select { |p| p.value == num && p.send(flip(symbol)) == last.first.send(flip(symbol)) }.count == 0
|
226
|
+
final = arr + last
|
227
|
+
places = final.map { |m| m.send(symbol) }.uniq
|
228
|
+
remaining_points.select { |p| places.include?(p.send(symbol)) && (!final.include?(p)) }.each do |poi|
|
229
|
+
poi.nums = poi.nums - [num]
|
228
230
|
end
|
229
231
|
end
|
230
232
|
end
|
data/lib/sudoku_solver/point.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative 'container'
|
2
1
|
require 'set'
|
3
2
|
|
4
3
|
class Point
|
@@ -16,7 +15,6 @@ class Point
|
|
16
15
|
@nums.sort
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
18
|
def share(point)
|
21
19
|
a = []
|
22
20
|
a << :box if @box == point.box
|
@@ -62,10 +60,5 @@ class Point
|
|
62
60
|
@position.y
|
63
61
|
end
|
64
62
|
|
65
|
-
def blank_spaces
|
66
|
-
[(position.y / 3) * 3 + (position.x / 3), position.y, position.x]
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
63
|
end
|
71
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sudoku-jedi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ajn123
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -183,17 +183,10 @@ files:
|
|
183
183
|
- Rakefile
|
184
184
|
- bin/sudoku-jedi
|
185
185
|
- lib/sudoku_solver.rb
|
186
|
-
- lib/sudoku_solver/box.rb
|
187
|
-
- lib/sudoku_solver/cell.rb
|
188
186
|
- lib/sudoku_solver/cli.rb
|
189
|
-
- lib/sudoku_solver/column.rb
|
190
|
-
- lib/sudoku_solver/container.rb
|
191
187
|
- lib/sudoku_solver/grid.rb
|
192
188
|
- lib/sudoku_solver/point.rb
|
193
|
-
- lib/sudoku_solver/row.rb
|
194
189
|
- lib/sudoku_solver/version.rb
|
195
|
-
- spec/box_spec.rb
|
196
|
-
- spec/cell_spec.rb
|
197
190
|
- spec/grid_spec.rb
|
198
191
|
- spec/spec_helper.rb
|
199
192
|
- sudoku_solver.gemspec
|
@@ -222,7 +215,5 @@ signing_key:
|
|
222
215
|
specification_version: 4
|
223
216
|
summary: Solves a sudoku puzzle
|
224
217
|
test_files:
|
225
|
-
- spec/box_spec.rb
|
226
|
-
- spec/cell_spec.rb
|
227
218
|
- spec/grid_spec.rb
|
228
219
|
- spec/spec_helper.rb
|
data/lib/sudoku_solver/box.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require_relative 'container'
|
2
|
-
|
3
|
-
class Box < Container
|
4
|
-
attr_accessor :box, :position
|
5
|
-
|
6
|
-
def initialize(arr, y=0, x=0)
|
7
|
-
super(arr)
|
8
|
-
Struct.new("Coordinate", :x, :y) if !Struct::const_defined? "Coordinate"
|
9
|
-
@position = Struct::Coordinate.new(x, y)
|
10
|
-
end
|
11
|
-
|
12
|
-
def blank_spaces
|
13
|
-
[(position.y / 3) * 3 + (position.x / 3), position.y, position.x]
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/lib/sudoku_solver/cell.rb
DELETED
data/lib/sudoku_solver/column.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class Container
|
2
|
-
|
3
|
-
attr_accessor :arr, :remaining_blocks
|
4
|
-
def initialize(arr)
|
5
|
-
@arr = arr
|
6
|
-
end
|
7
|
-
# Find the missing elements in the section
|
8
|
-
def difference
|
9
|
-
complete
|
10
|
-
remaining
|
11
|
-
end
|
12
|
-
|
13
|
-
def remaining
|
14
|
-
Array(1..9) - arr
|
15
|
-
end
|
16
|
-
|
17
|
-
def arr
|
18
|
-
@arr.map!(&:to_i)
|
19
|
-
end
|
20
|
-
|
21
|
-
def contain?(num)
|
22
|
-
complete
|
23
|
-
arr.include? num
|
24
|
-
end
|
25
|
-
|
26
|
-
def pencil_in
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def complete
|
31
|
-
if remaining.count == 1
|
32
|
-
arr.map { |elem| elem == 0 ? remaining.first : elem }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/sudoku_solver/row.rb
DELETED
data/spec/box_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe Box do
|
3
|
-
let(:box) { Box.new([1,2,4,5,6,7,8,9], 0, 5)}
|
4
|
-
context "Coordinates" do
|
5
|
-
it "is correct" do
|
6
|
-
expect(box.blank_spaces).to eql([1, 0, 5])
|
7
|
-
@let_box = Box.new([], 8, 8)
|
8
|
-
expect(@let_box.blank_spaces).to eql([8, 8, 8])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
context "#differance" do
|
12
|
-
it "shows the incorrect differance" do
|
13
|
-
expect(box.difference).to_not eql(Array(5..9))
|
14
|
-
end
|
15
|
-
it "show the correct differance" do
|
16
|
-
expect(box.difference).to eql([3])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
context "#complete" do
|
20
|
-
it "completes the cell" do
|
21
|
-
@in_box = Box.new([1,0,3,4,5,6,7,8,9])
|
22
|
-
expect(@in_box.complete).to eql(Array(1..9))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|