word_search 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.rubocop.yml +8 -5
- data/.ruby-version +1 -1
- data/.travis.yml +3 -2
- data/Gemfile +2 -1
- data/README.md +26 -4
- data/Rakefile +26 -12
- data/bin/console +5 -4
- data/bin/test +19 -0
- data/docs/Gemfile +8 -7
- data/docs/Gemfile.lock +31 -31
- data/docs/Rakefile +2 -1
- data/docs/config.rb +4 -3
- data/docs/source/images/logo.png +0 -0
- data/docs/source/images/search.png +0 -0
- data/docs/source/index.html.haml +49 -7
- data/docs/source/layouts/layout.html.haml +7 -9
- data/docs/source/stylesheets/site.css.sass +83 -0
- data/docs/vendor/cache/activesupport-5.0.1.gem +0 -0
- data/docs/vendor/cache/addressable-2.5.0.gem +0 -0
- data/docs/vendor/cache/backports-3.6.8.gem +0 -0
- data/docs/vendor/cache/coffee-script-2.4.1.gem +0 -0
- data/docs/vendor/cache/coffee-script-source-1.12.2.gem +0 -0
- data/docs/vendor/cache/compass-import-once-1.0.5.gem +0 -0
- data/docs/vendor/cache/concurrent-ruby-1.0.4.gem +0 -0
- data/docs/vendor/cache/contracts-0.13.0.gem +0 -0
- data/docs/vendor/cache/dotenv-2.1.1.gem +0 -0
- data/docs/vendor/cache/em-websocket-0.5.1.gem +0 -0
- data/docs/vendor/cache/erubis-2.7.0.gem +0 -0
- data/docs/vendor/cache/eventmachine-1.2.1.gem +0 -0
- data/docs/vendor/cache/execjs-2.7.0.gem +0 -0
- data/docs/vendor/cache/fast_blank-1.0.0.gem +0 -0
- data/docs/vendor/cache/fastimage-2.0.1.gem +0 -0
- data/docs/vendor/cache/ffi-1.9.14.gem +0 -0
- data/docs/vendor/cache/haml-4.0.7.gem +0 -0
- data/docs/vendor/cache/hamster-3.0.0.gem +0 -0
- data/docs/vendor/cache/hashie-3.4.6.gem +0 -0
- data/docs/vendor/cache/http_parser.rb-0.6.0.gem +0 -0
- data/docs/vendor/cache/i18n-0.7.0.gem +0 -0
- data/docs/vendor/cache/kramdown-1.13.2.gem +0 -0
- data/docs/vendor/cache/listen-3.0.8.gem +0 -0
- data/docs/vendor/cache/memoist-0.15.0.gem +0 -0
- data/docs/vendor/cache/middleman-4.2.0.gem +0 -0
- data/docs/vendor/cache/middleman-cli-4.2.0.gem +0 -0
- data/docs/vendor/cache/middleman-core-4.2.0.gem +0 -0
- data/docs/vendor/cache/middleman-gh-pages-0.3.1.gem +0 -0
- data/docs/vendor/cache/middleman-livereload-3.4.6.gem +0 -0
- data/docs/vendor/cache/minitest-5.10.1.gem +0 -0
- data/docs/vendor/cache/padrino-helpers-0.13.3.3.gem +0 -0
- data/docs/vendor/cache/padrino-support-0.13.3.3.gem +0 -0
- data/docs/vendor/cache/parallel-1.10.0.gem +0 -0
- data/docs/vendor/cache/public_suffix-2.0.5.gem +0 -0
- data/docs/vendor/cache/rack-2.0.1.gem +0 -0
- data/docs/vendor/cache/rack-livereload-0.3.16.gem +0 -0
- data/docs/vendor/cache/rake-12.0.0.gem +0 -0
- data/docs/vendor/cache/rb-fsevent-0.9.8.gem +0 -0
- data/docs/vendor/cache/rb-inotify-0.9.7.gem +0 -0
- data/docs/vendor/cache/sass-3.4.23.gem +0 -0
- data/docs/vendor/cache/servolux-0.12.0.gem +0 -0
- data/docs/vendor/cache/thor-0.19.4.gem +0 -0
- data/docs/vendor/cache/thread_safe-0.3.5.gem +0 -0
- data/docs/vendor/cache/tilt-2.0.5.gem +0 -0
- data/docs/vendor/cache/tzinfo-1.2.2.gem +0 -0
- data/docs/vendor/cache/uglifier-3.0.4.gem +0 -0
- data/lib/word_search.rb +25 -24
- data/lib/word_search/catalog.rb +1 -0
- data/lib/word_search/generator.rb +9 -3
- data/lib/word_search/generator/base.rb +50 -2
- data/lib/word_search/plane.rb +1 -0
- data/lib/word_search/plane/base.rb +25 -2
- data/lib/word_search/position_word/base.rb +32 -3
- data/lib/word_search/solver.rb +113 -3
- data/lib/word_search/three_dimensional/direction.rb +1 -0
- data/lib/word_search/three_dimensional/generator.rb +1 -18
- data/lib/word_search/three_dimensional/plane.rb +8 -1
- data/lib/word_search/three_dimensional/point.rb +5 -0
- data/lib/word_search/three_dimensional/position_word.rb +7 -0
- data/lib/word_search/two_dimensional/direction.rb +1 -0
- data/lib/word_search/two_dimensional/generator.rb +1 -18
- data/lib/word_search/two_dimensional/plane.rb +6 -1
- data/lib/word_search/two_dimensional/point.rb +5 -0
- data/lib/word_search/two_dimensional/position_word.rb +7 -0
- data/lib/word_search/version.rb +2 -1
- data/lib/word_search/word_bank.rb +4 -3
- data/vendor/cache/activemodel-5.0.1.gem +0 -0
- data/vendor/cache/activesupport-5.0.1.gem +0 -0
- data/vendor/cache/codeclimate-test-reporter-1.0.4.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.0.4.gem +0 -0
- data/vendor/cache/metaclass-0.0.4.gem +0 -0
- data/vendor/cache/minitest-5.10.1.gem +0 -0
- data/vendor/cache/mocha-1.2.1.gem +0 -0
- data/vendor/cache/parser-2.3.3.1.gem +0 -0
- data/vendor/cache/rainbow-2.2.1.gem +0 -0
- data/vendor/cache/rake-12.0.0.gem +0 -0
- data/vendor/cache/rspec-core-3.5.4.gem +0 -0
- data/vendor/cache/rubocop-0.46.0.gem +0 -0
- data/vendor/cache/ruby-enum-0.6.0.gem +0 -0
- data/vendor/cache/unicode-display_width-1.1.2.gem +0 -0
- data/word_search.gemspec +23 -21
- metadata +91 -29
- data/docs/source/images/github-light.png +0 -0
- data/docs/source/images/github.png +0 -0
- data/docs/source/stylesheets/site.css.scss +0 -71
- data/lib/solution.rb +0 -67
- data/vendor/cache/activemodel-5.0.0.1.gem +0 -0
- data/vendor/cache/activesupport-5.0.0.1.gem +0 -0
- data/vendor/cache/codeclimate-test-reporter-0.6.0.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.0.2.gem +0 -0
- data/vendor/cache/minitest-5.9.0.gem +0 -0
- data/vendor/cache/parser-2.3.1.2.gem +0 -0
- data/vendor/cache/rainbow-2.1.0.gem +0 -0
- data/vendor/cache/rake-10.5.0.gem +0 -0
- data/vendor/cache/rspec-core-3.5.2.gem +0 -0
- data/vendor/cache/rubocop-0.42.0.gem +0 -0
- data/vendor/cache/ruby-enum-0.5.0.gem +0 -0
- data/vendor/cache/unicode-display_width-1.1.0.gem +0 -0
@@ -3,18 +3,16 @@
|
|
3
3
|
%head
|
4
4
|
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
|
5
5
|
%meta{content: "IE=edge", "http-equiv" => "X-UA-Compatible"}/
|
6
|
-
%meta{:
|
7
|
-
%meta{content: "width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no", :
|
6
|
+
%meta{charset: "utf-8"}/
|
7
|
+
%meta{content: "width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no", name: "viewport"}/
|
8
8
|
|
9
|
-
%script{:
|
10
|
-
%link{:
|
9
|
+
%script{src: "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"}
|
10
|
+
%link{href: "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/atom-one-dark.min.css", rel: "stylesheet"}/
|
11
11
|
|
12
12
|
%title= current_page.data.title || "Middleman"
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
= stylesheet_link_tag :site
|
17
|
-
= javascript_include_tag :all
|
13
|
+
= favicon_tag 'images/search.png'
|
14
|
+
= stylesheet_link_tag "//fonts.googleapis.com/css?family=Lato:300,400", "//fonts.googleapis.com/css?family=Droid+Sans+Mono", :site
|
15
|
+
= javascript_include_tag "//use.fontawesome.com/1118bc452f.js", :all
|
18
16
|
|
19
17
|
%body{:class => page_classes}
|
20
18
|
= yield
|
@@ -0,0 +1,83 @@
|
|
1
|
+
@charset "utf-8"
|
2
|
+
@import normalize
|
3
|
+
|
4
|
+
body
|
5
|
+
background: #F9F7E9
|
6
|
+
font-family: "Lato", "Helvetica Neue", Helvetica, Arial, sans-serif
|
7
|
+
|
8
|
+
h1
|
9
|
+
color: #66BEAD
|
10
|
+
font-family: "Lato", "Helvetica Neue", Helvetica, Arial, sans-serif
|
11
|
+
font-size: 3.5em
|
12
|
+
font-weight: 400
|
13
|
+
margin: 0
|
14
|
+
padding: 20px
|
15
|
+
|
16
|
+
.container
|
17
|
+
width: 700px
|
18
|
+
max-width: 90%
|
19
|
+
margin: auto
|
20
|
+
|
21
|
+
.hljs
|
22
|
+
padding: 20px
|
23
|
+
font-family: 'Droid Sans Mono', monospace
|
24
|
+
background: rgba(40, 44, 52, 0.8)
|
25
|
+
|
26
|
+
.center
|
27
|
+
text-align: center
|
28
|
+
|
29
|
+
h4, p, h3
|
30
|
+
color: #66BEAD
|
31
|
+
|
32
|
+
.fork .block
|
33
|
+
justify-content: flex-end
|
34
|
+
display: flex
|
35
|
+
flex-direction: row
|
36
|
+
|
37
|
+
a
|
38
|
+
display: flex
|
39
|
+
flex-direction: row
|
40
|
+
align-items: center
|
41
|
+
cursor: pointer
|
42
|
+
margin: 7px
|
43
|
+
margin-right: 13px
|
44
|
+
padding: 10px
|
45
|
+
color: #66BEAD
|
46
|
+
background: transparent
|
47
|
+
transition: all 0.5s ease
|
48
|
+
text-decoration: none
|
49
|
+
|
50
|
+
i
|
51
|
+
font-size: 27px
|
52
|
+
margin-right: 10px
|
53
|
+
|
54
|
+
&:hover
|
55
|
+
color: #167C80
|
56
|
+
|
57
|
+
#np_logo_container
|
58
|
+
margin-top: 150px
|
59
|
+
margin-bottom: 25px
|
60
|
+
width: 100%
|
61
|
+
height: 75px
|
62
|
+
display: flex
|
63
|
+
align-items: center
|
64
|
+
justify-content: center
|
65
|
+
img
|
66
|
+
height: 100%
|
67
|
+
margin: 0 20px
|
68
|
+
a
|
69
|
+
width: 45px
|
70
|
+
height: 45px
|
71
|
+
background: #66BEAD
|
72
|
+
border-radius: 50%
|
73
|
+
display: flex
|
74
|
+
align-items: center
|
75
|
+
justify-content: center
|
76
|
+
text-decoration: none
|
77
|
+
color: #F9F7E9
|
78
|
+
cursor: pointer
|
79
|
+
i
|
80
|
+
font-size: 30px
|
81
|
+
|
82
|
+
.hljs-comment, .hljs-quote
|
83
|
+
color: #79808f !important
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/word_search.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_model"
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/all"
|
5
|
+
require "csv"
|
6
|
+
require "ruby-enum"
|
6
7
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
8
|
+
require "word_search/version"
|
9
|
+
require "word_search/plane"
|
10
|
+
require "word_search/word_bank"
|
11
|
+
require "word_search/generator"
|
12
|
+
require "word_search/catalog"
|
13
|
+
require "word_search/solver"
|
13
14
|
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
15
|
+
require "word_search/plane/base"
|
16
|
+
require "word_search/generator/base"
|
17
|
+
require "word_search/position_word/base"
|
17
18
|
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
19
|
+
require "word_search/three_dimensional/plane"
|
20
|
+
require "word_search/three_dimensional/point"
|
21
|
+
require "word_search/three_dimensional/direction"
|
22
|
+
require "word_search/three_dimensional/generator"
|
23
|
+
require "word_search/three_dimensional/position_word"
|
23
24
|
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
25
|
+
require "word_search/two_dimensional/plane"
|
26
|
+
require "word_search/two_dimensional/point"
|
27
|
+
require "word_search/two_dimensional/direction"
|
28
|
+
require "word_search/two_dimensional/generator"
|
29
|
+
require "word_search/two_dimensional/position_word"
|
29
30
|
|
30
31
|
module WordSearch
|
31
32
|
end
|
data/lib/word_search/catalog.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module WordSearch
|
2
3
|
class Generator < SimpleDelegator
|
3
4
|
include ActiveModel::Validations
|
@@ -23,6 +24,7 @@ module WordSearch
|
|
23
24
|
|
24
25
|
if valid?
|
25
26
|
plane.add_letters
|
27
|
+
write_solution
|
26
28
|
plane
|
27
29
|
else
|
28
30
|
false
|
@@ -42,19 +44,23 @@ module WordSearch
|
|
42
44
|
def words_too_long
|
43
45
|
"#{word_bank.longest_words.join(' and ')} "\
|
44
46
|
"#{'is'.pluralize(word_bank.longest_words.count)} "\
|
45
|
-
|
47
|
+
"too long for the word search"
|
46
48
|
end
|
47
49
|
|
48
50
|
def valid_plane?
|
51
|
+
return if plane.valid?
|
52
|
+
|
49
53
|
plane.errors.full_messages.each do |msg|
|
50
54
|
errors.add(:base, msg)
|
51
|
-
end
|
55
|
+
end
|
52
56
|
end
|
53
57
|
|
54
58
|
def valid_word_bank?
|
59
|
+
return if word_bank.valid?
|
60
|
+
|
55
61
|
word_bank.errors.full_messages.each do |msg|
|
56
62
|
errors.add(:base, msg)
|
57
|
-
end
|
63
|
+
end
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
@@ -1,28 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module WordSearch
|
2
3
|
class Generator
|
3
4
|
class Base
|
4
5
|
include ActiveModel::Validations
|
5
6
|
|
6
|
-
attr_accessor :plane, :word_bank, :used_coordinates
|
7
|
+
attr_accessor :plane, :word_bank, :used_coordinates, :positions
|
7
8
|
delegate :to_s, :pto_s, :print, :catalog, to: :plane
|
8
9
|
|
10
|
+
def directions
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
9
14
|
def initialize(plane, word_bank)
|
10
15
|
@plane = plane
|
11
16
|
@word_bank = word_bank
|
12
17
|
@used_coordinates = []
|
18
|
+
@positions = {}
|
13
19
|
end
|
14
20
|
|
15
21
|
def perform
|
16
22
|
word_bank.each do |word|
|
17
|
-
place_word(word)
|
23
|
+
@positions[word] = place_word(word)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_solution
|
28
|
+
file_name = "solution_#{plane.digest}"
|
29
|
+
File.open(file_name, "w") do |f|
|
30
|
+
solution = positions.map do |_word, letter_positions|
|
31
|
+
letter_positions.map do |letter, position|
|
32
|
+
"#{letter.split('-')[0]} #{position.values}"
|
33
|
+
end.join("\n")
|
34
|
+
end.join("\n---\n")
|
35
|
+
|
36
|
+
f.write solution
|
18
37
|
end
|
19
38
|
end
|
20
39
|
|
21
40
|
private
|
22
41
|
|
42
|
+
def place_word(word)
|
43
|
+
placed = false
|
44
|
+
until placed || used_coordinates.uniq.count == plane.total_points
|
45
|
+
placed = position_word(word)
|
46
|
+
end
|
47
|
+
|
48
|
+
word_bank.errors.add(word, "cannot be placed") if placed.blank?
|
49
|
+
placed
|
50
|
+
end
|
51
|
+
|
52
|
+
def position_word(word)
|
53
|
+
used_coordinates << (coordinate = random_point)
|
54
|
+
position = false
|
55
|
+
|
56
|
+
directions.find do |direction|
|
57
|
+
dimension = plane.two_dimensional? ? TwoDimensional : ThreeDimensional
|
58
|
+
position =
|
59
|
+
dimension::PositionWord.new(
|
60
|
+
plane, word, direction, coordinate
|
61
|
+
).perform
|
62
|
+
end
|
63
|
+
|
64
|
+
position
|
65
|
+
end
|
66
|
+
|
23
67
|
def random(number)
|
24
68
|
SecureRandom.random_number number
|
25
69
|
end
|
70
|
+
|
71
|
+
def random_point
|
72
|
+
raise NotImplementedError
|
73
|
+
end
|
26
74
|
end
|
27
75
|
end
|
28
76
|
end
|
data/lib/word_search/plane.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module WordSearch
|
2
3
|
class Plane
|
3
4
|
class Base < Hash
|
4
5
|
include ActiveModel::Validations
|
5
6
|
|
7
|
+
LETTERS = ("a".."z").to_a
|
8
|
+
|
6
9
|
attr_accessor :x, :y, :catalog
|
7
10
|
|
8
11
|
validates :x, :y, numericality: { greater_than_or_equal_to: 2 }
|
9
12
|
|
10
13
|
def print(file_name = nil)
|
11
|
-
File.open(file_name ||
|
14
|
+
File.open(file_name || "word_search", "w") { |f| f.write to_s }
|
12
15
|
end
|
13
16
|
|
14
17
|
def random_letter
|
15
|
-
|
18
|
+
LETTERS.sample
|
16
19
|
end
|
17
20
|
|
18
21
|
def two_dimensional?
|
@@ -35,6 +38,26 @@ module WordSearch
|
|
35
38
|
puts to_s
|
36
39
|
end
|
37
40
|
|
41
|
+
def digest
|
42
|
+
Digest::MD5.hexdigest(to_s)
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
raise NotImplementedError
|
47
|
+
end
|
48
|
+
|
49
|
+
def total_points
|
50
|
+
raise NotImplementedError
|
51
|
+
end
|
52
|
+
|
53
|
+
def max
|
54
|
+
raise NotImplementedError
|
55
|
+
end
|
56
|
+
|
57
|
+
def directions
|
58
|
+
raise NotImplementedError
|
59
|
+
end
|
60
|
+
|
38
61
|
private
|
39
62
|
|
40
63
|
def initialize_plane
|