sudoku_maker 0.0.1

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.
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ ruby:
3
+ - 2.0.0
4
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sudoku_maker.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 hooor
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ master: ![master](https://travis-ci.org/hooor/sudoku_maker.svg?branch=master "")
2
+
3
+ # SudokuMaker
4
+
5
+ SudokuMaker which can make sudoku 4x4, 9x9, 16x16, …, 100x100.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sudoku_maker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sudoku_maker
22
+
23
+ ## Usage
24
+
25
+ SudokuMaker.make ARGS Int(4, 9, 16, 25, 36, 49, 64, 81, 100)
26
+
27
+ args is a block number (generally => 9)
28
+
29
+ args is only permited in (4, 9, 16, 25, 36, 49, 64, 81, 100)
30
+
31
+ return value is array
32
+
33
+ e.g. SudokumMaker.make 4 #=> [1, 3, 4, 2, 4, 2, 3, 1, 2, 4, 1, 3, 3, 1, 2, 4]
34
+
35
+ means
36
+
37
+ ```
38
+ -----------------
39
+ | 1 | 3 | 4 | 2 |
40
+ -----------------
41
+ | 4 | 2 | 3 | 1 |
42
+ -----------------
43
+ | 2 | 4 | 1 | 3 |
44
+ -----------------
45
+ | 3 | 1 | 2 | 4 |
46
+ -----------------
47
+ ```
48
+
49
+ ## Demo
50
+
51
+ ```ruby
52
+ require "sudoku_maker"
53
+
54
+ p SudokuMaker.make 9
55
+
56
+ #=> [4, 5, 7, 2, 6, 9, 1, 3, 8, 2, 6, 9, 8, 3, 1, 5, 4, 7, 3, 1, 8, 4, 5, 7, 9, 6, 2, 5, 7, 4, 6, 9, 2, 8, 1, 3, 1, 8, 3, 5, 7, 4, 2, 9, 6, 6, 9, 2, 3, 1, 8, 7, 5, 4, 8, 3, 1, 7, 4, 5, 6, 2, 9, 7, 4, 5, 9, 2, 6, 3, 8, 1, 9, 2, 6, 1, 8, 3, 4, 7, 5]
57
+
58
+ p Sudokumaker.Make 25
59
+
60
+ #=> [6, 7, 5, 8, 3, 16, 17, 11, 18, 20, 24, 25, 1, 22, 23, 2, 12, 10, 13, 14, 19, 4, 15, 21, 9, 9, 4, 19, 21, 15, 7, 8, 5, 3, 6, 18, 16, 11, 20, 17, 24, 25, 22, 1, 23, 10, 2, 13, 12, 14, 16, 11, 17, 18, 20, 1, 24, 23, 22, 25, 10, 13, 14, 12, 2, 19, 15, 21, 9, 4, 8, 5, 6, 3, 7, 13, 14, 2, 10, 12, 9, 19, 4, 21, 15, 8, 6, 7, 3, 5, 17, 20, 18, 16, 11, 24, 23, 25, 22, 1, 25, 1, 23, 24, 22, 13, 2, 14, 10, 12, 19, 15, 9, 21, 4, 5, 3, 8, 6, 7, 17, 11, 20, 18, 16, 15, 9, 4, 19, 21, 6, 5, 7, 8, 3, 17, 20, 16, 18, 11, 23, 22, 24, 25, 1, 2, 14, 12, 10, 13, 3, 6, 7, 5, 8, 20, 11, 16, 17, 18, 23, 22, 25, 24, 1, 14, 10, 2, 12, 13, 4, 9, 21, 19, 15, 22, 25, 1, 23, 24, 12, 14, 13, 2, 10, 4, 21, 15, 19, 9, 7, 8, 5, 3, 6, 11, 16, 18, 17, 20, 20, 16, 11, 17, 18, 25, 23, 1, 24, 22, 2, 12, 13, 10, 14, 4, 21, 19, 15, 9, 5, 7, 3, 8, 6, 12, 13, 14, 2, 10, 15, 4, 9, 19, 21, 5, 3, 6, 8, 7, 11, 18, 17, 20, 16, 23, 1, 22, 24, 25, 4, 19, 21, 15, 9, 5, 3, 8, 6, 7, 20, 11, 17, 16, 18, 22, 1, 25, 23, 24, 12, 10, 14, 13, 2, 7, 5, 8, 3, 6, 11, 18, 17, 20, 16, 22, 1, 23, 25, 24, 10, 13, 12, 14, 2, 21, 19, 9, 15, 4, 14, 2, 10, 12, 13, 4, 21, 19, 15, 9, 3, 7, 5, 6, 8, 18, 16, 20, 11, 17, 22, 24, 1, 25, 23, 11, 17, 18, 20, 16, 23, 22, 24, 25, 1, 12, 14, 2, 13, 10, 21, 9, 15, 4, 19, 3, 8, 7, 6, 5, 1, 23, 24, 22, 25, 14, 10, 2, 12, 13, 21, 9, 4, 15, 19, 8, 6, 3, 7, 5, 18, 17, 16, 20, 11, 18, 20, 16, 11, 17, 22, 1, 25, 23, 24, 14, 10, 12, 2, 13, 9, 19, 4, 21, 15, 7, 6, 8, 5, 3, 10, 12, 13, 14, 2, 21, 9, 15, 4, 19, 7, 8, 3, 5, 6, 16, 17, 11, 18, 20, 1, 25, 24, 23, 22, 8, 3, 6, 7, 5, 18, 16, 20, 11, 17, 1, 24, 22, 23, 25, 13, 2, 14, 10, 12, 9, 15, 19, 4, 21, 24, 22, 25, 1, 23, 10, 13, 12, 14, 2, 9, 19, 21, 4, 15, 6, 5, 7, 8, 3, 16, 20, 17, 11, 18, 21, 15, 9, 4, 19, 3, 7, 6, 5, 8, 11, 18, 20, 17, 16, 1, 24, 23, 22, 25, 14, 13, 10, 2, 12, 23, 24, 22, 25, 1, 2, 12, 10, 13, 14, 15, 4, 19, 9, 21, 3, 7, 6, 5, 8, 20, 18, 11, 16, 17, 5, 8, 3, 6, 7, 17, 20, 18, 16, 11, 25, 23, 24, 1, 22, 12, 14, 13, 2, 10, 15, 21, 4, 9, 19, 2, 10, 12, 13, 14, 19, 15, 21, 9, 4, 6, 5, 8, 7, 3, 20, 11, 16, 17, 18, 25, 22, 23, 1, 24, 17, 18, 20, 16, 11, 24, 25, 22, 1, 23, 13, 2, 10, 14, 12, 15, 4, 9, 19, 21, 6, 3, 5, 7, 8, 19, 21, 15, 9, 4, 8, 6, 3, 7, 5, 16, 17, 18, 11, 20, 25, 23, 1, 24, 22, 13, 12, 2, 14, 10]
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( https://github.com/[my-github-username]/sudoku_maker/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ require "sudoku_maker/version"
2
+ require "sudoku_maker/maker"
3
+ require "sudoku_maker/utils/all_block_numbers"
4
+
5
+ module SudokuMaker
6
+ class << self
7
+ def make(num)
8
+ ret = []
9
+ if check(num)
10
+ maker = Maker.new(num)
11
+ ret = maker.exec
12
+ else
13
+ print "invalid args. only permited in #{AllBlockNumbers::BLOCK_NUMBERS}"
14
+ end
15
+ return ret
16
+ end
17
+
18
+ private
19
+
20
+ # check args
21
+ def check(num)
22
+ if AllBlockNumbers::BLOCK_NUMBERS.include?(num)
23
+ return true
24
+ else
25
+ return false
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,87 @@
1
+
2
+ module SudokuMaker
3
+ class Maker
4
+ def initialize(num)
5
+ @block_num = num
6
+ @decision_num = Math.sqrt(num).to_i
7
+ end
8
+
9
+ def exec
10
+ s = make_source()
11
+ s = shuffle_block_row(s)
12
+ s = switch_row_column(s)
13
+ s = shuffle_block_row(s)
14
+
15
+ # format to array
16
+ ret = []
17
+ s.each do |arr|
18
+ arr.each do |v|
19
+ ret = ret + v
20
+ end
21
+ end
22
+
23
+ return ret
24
+ end
25
+
26
+ private
27
+
28
+ def make_source()
29
+ arr = []
30
+ for i in 1..@block_num do
31
+ arr.push(i)
32
+ end
33
+ arr = arr.shuffle
34
+ d = []
35
+ for i in 0..@block_num - 1 do
36
+ num = i % @decision_num
37
+ copied = arr.clone
38
+ # initialize
39
+ d[num] = [] unless d[num]
40
+ d[num].push(copied)
41
+ arr.push(arr.shift)
42
+ end
43
+
44
+ return d
45
+ end
46
+
47
+ def shuffle_block_row(indata)
48
+ # block shuffle
49
+ indata = indata.shuffle
50
+ # row shuffle in each block
51
+ for i in 0..@decision_num - 1 do
52
+ indata[i] = indata[i].shuffle
53
+ end
54
+
55
+ return indata
56
+ end
57
+
58
+ def switch_row_column(indata)
59
+ # format indata to array
60
+ tmp = []
61
+ indata.each do |arr|
62
+ arr.each do |v|
63
+ tmp = tmp + v
64
+ end
65
+ end
66
+
67
+ # switch row and column
68
+ cnt = 1
69
+ d = []
70
+ tmp_d = []
71
+ for i in 0..@block_num - 1 do
72
+ j_arr = []
73
+ for j in 0..@block_num - 1 do
74
+ j_arr.push(tmp[i + j * @block_num])
75
+ end
76
+ tmp_d.push(j_arr)
77
+ if (cnt % @decision_num == 0)
78
+ d.push (tmp_d)
79
+ tmp_d = []
80
+ end
81
+ cnt = cnt + 1
82
+ end
83
+
84
+ return d
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,4 @@
1
+ module AllBlockNumbers
2
+ BLOCK_NUMBERS = [4, 9, 16, 25, 36, 49, 64, 81, 100]
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ module SudokuMaker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sudoku_maker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sudoku_maker"
8
+ spec.version = SudokuMaker::VERSION
9
+ spec.authors = ["yokkora"]
10
+ spec.email = ["mail@yokkora.info"]
11
+ spec.summary = %q{Sudoku maker which can make 4x4, 9x9, 16x16, …, 100x100}
12
+ spec.description = %q{Sudoku maker which can make 4x4, 9x9, 16x16, …, 100x100}
13
+ spec.homepage = "https://github.com/hooor/sudoku_maker"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sudoku_maker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - yokkora
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ description: Sudoku maker which can make 4x4, 9x9, 16x16, …, 100x100
47
+ email:
48
+ - mail@yokkora.info
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .travis.yml
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/sudoku_maker.rb
60
+ - lib/sudoku_maker/maker.rb
61
+ - lib/sudoku_maker/utils/all_block_numbers.rb
62
+ - lib/sudoku_maker/version.rb
63
+ - sudoku_maker.gemspec
64
+ homepage: https://github.com/hooor/sudoku_maker
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: 2114898798346807998
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: 2114898798346807998
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.23
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Sudoku maker which can make 4x4, 9x9, 16x16, …, 100x100
95
+ test_files: []