sudoku_builder 0.1.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock DELETED
@@ -1,17 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sudoku_builder (0.1.2)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- rake (10.4.2)
10
-
11
- PLATFORMS
12
- ruby
13
-
14
- DEPENDENCIES
15
- bundler (~> 1.9)
16
- rake (~> 10.0)
17
- sudoku_builder!
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Colin Walker
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
@@ -1,40 +0,0 @@
1
- module SudokuBuilder
2
- class Sudoku
3
-
4
- # this method builds the 'c,r,g' arguments which are used as local variables within
5
- # the main solve method to easily check whether a value is part of a row, column or
6
- # grid. This is done by getting the keys of each item with matching row coordinates,
7
- # column coordinates and grid coordinates, and adding all the values of each key to
8
- # the c,r,g.
9
- def build_crg(key,c,r,g,sud)
10
- coord = {
11
- 0=> [0,0,1], 1=> [1,0,1], 2=> [2,0,1], 3=> [3,0,4], 4=> [4,0,4], 5=> [5,0,4], 6=> [6,0,7], 7=> [7,0,7], 8=> [8,0,7],
12
- 9=> [0,1,1], 10=>[1,1,1], 11=>[2,1,1], 12=>[3,1,4], 13=>[4,1,4], 14=>[5,1,4], 15=>[6,1,7], 16=>[7,1,7], 17=>[8,1,7],
13
- 18=>[0,2,1], 19=>[1,2,1], 20=>[2,2,1], 21=>[3,2,4], 22=>[4,2,4], 23=>[5,2,4], 24=>[6,2,7], 25=>[7,2,7], 26=>[8,2,7],
14
- 27=>[0,3,2], 28=>[1,3,2], 29=>[2,3,2], 30=>[3,3,5], 31=>[4,3,5], 32=>[5,3,5], 33=>[6,3,8], 34=>[7,3,8], 35=>[8,3,8],
15
- 36=>[0,4,2], 37=>[1,4,2], 38=>[2,4,2], 39=>[3,4,5], 40=>[4,4,5], 41=>[5,4,5], 42=>[6,4,8], 43=>[7,4,8], 44=>[8,4,8],
16
- 45=>[0,5,2], 46=>[1,5,2], 47=>[2,5,2], 48=>[3,5,5], 49=>[4,5,5], 50=>[5,5,5], 51=>[6,5,8], 52=>[7,5,8], 53=>[8,5,8],
17
- 54=>[0,6,3], 55=>[1,6,3], 56=>[2,6,3], 57=>[3,6,6], 58=>[4,6,6], 59=>[5,6,6], 60=>[6,6,9], 61=>[7,6,9], 62=>[8,6,9],
18
- 63=>[0,7,3], 64=>[1,7,3], 65=>[2,7,3], 66=>[3,7,6], 67=>[4,7,6], 68=>[5,7,6], 69=>[6,7,9], 70=>[7,7,9], 71=>[8,7,9],
19
- 72=>[0,8,3], 73=>[1,8,3], 74=>[2,8,3], 75=>[3,8,6], 76=>[4,8,6], 77=>[5,8,6], 78=>[6,8,9], 79=>[7,8,9], 80=>[8,8,9]
20
- }
21
- coord.select { |k,v| v[0] == coord[key][0] }.keys.each { |k| c << sud[k] }
22
- coord.select { |k,v| v[1] == coord[key][1] }.keys.each { |k| r << sud[k] }
23
- coord.select { |k,v| v[2] == coord[key][2] }.keys.each { |k| g << sud[k] }
24
- end
25
-
26
- def check?(val,c,r,g)
27
- !c.flatten.include?(val) && !r.flatten.include?(val) && !g.flatten.include?(val)
28
- end
29
-
30
- def pristine
31
- sud = {} ; q = 0
32
- 81.times do
33
- sud[q] = []
34
- q += 1
35
- end
36
- sud
37
- end
38
-
39
- end
40
- end