eulers_day_off 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/eulers_day_off.gemspec +22 -0
- data/lib/eulers_day_off/letter_generator.rb +13 -0
- data/lib/eulers_day_off/scorer.rb +34 -0
- data/lib/eulers_day_off/word_list.rb +16 -0
- data/lib/eulers_day_off/word_loader.rb +20 -0
- data/lib/eulers_day_off.rb +28 -0
- data/lib/version.rb +3 -0
- data/lib/word_list.txt +13979 -0
- data/spec/eulers_day_off_spec.rb +26 -0
- data/spec/letter_generator_spec.rb +20 -0
- data/spec/scorer_spec.rb +35 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/word_list_spec.rb +11 -0
- data/spec/word_loader_spec.rb +23 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Euler's Day Off
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'eulers_day_off'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install eulers_day_off
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "eulers_day_off"
|
8
|
+
gem.version = EulersDayOff::VERSION
|
9
|
+
gem.authors = ["Eric Koslow"]
|
10
|
+
gem.email = ["ekoslow+eulersdayoff@gmail.com"]
|
11
|
+
gem.description = %q{Scores Euler's Day Off boards}
|
12
|
+
gem.summary = %q{Scores Euler's Day Off boards}
|
13
|
+
gem.homepage = "https://github.com/ekosz/eulers_day_off"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module EulersDayOff
|
2
|
+
class Scorer
|
3
|
+
|
4
|
+
attr_writer :word_list
|
5
|
+
|
6
|
+
def initialize(word_list)
|
7
|
+
@word_list = word_list
|
8
|
+
end
|
9
|
+
|
10
|
+
def score(board)
|
11
|
+
_score_board(board) + _score_board(board.transpose)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def _score_board(board)
|
17
|
+
board.inject(0) do |acc, row|
|
18
|
+
return acc unless row.compact.length >= 3
|
19
|
+
acc + _score_row(row)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def _score_row(row)
|
24
|
+
(3..row.compact.size).to_a.reverse.each do |length|
|
25
|
+
row.each_cons(length) do |cons|
|
26
|
+
return length if @word_list.include?(cons.join)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
0
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module EulersDayOff
|
2
|
+
class WordLoader
|
3
|
+
|
4
|
+
attr_writer :file
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def populate_word_list(filter = EulersDayOff::WordList.new)
|
11
|
+
@file ||= File.new(@path)
|
12
|
+
|
13
|
+
@file.each_line do |line|
|
14
|
+
filter.insert line.chomp
|
15
|
+
end
|
16
|
+
|
17
|
+
filter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module EulersDayOff
|
4
|
+
|
5
|
+
|
6
|
+
def self.random_letters
|
7
|
+
LetterGenerator.new.generate
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.score(board)
|
11
|
+
Scorer.new(word_list).score(board)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.word_list
|
17
|
+
@word_list ||= begin
|
18
|
+
path = File.expand_path("../word_list.txt", __FILE__)
|
19
|
+
WordLoader.new(path).populate_word_list
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'eulers_day_off/letter_generator'
|
26
|
+
require 'eulers_day_off/word_list'
|
27
|
+
require 'eulers_day_off/word_loader'
|
28
|
+
require 'eulers_day_off/scorer'
|
data/lib/version.rb
ADDED