eulers_day_off 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
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,13 @@
1
+ module EulersDayOff
2
+ class LetterGenerator
3
+ attr_writer :letters
4
+
5
+ def initialize
6
+ @letters = ('a'..'z').to_a
7
+ end
8
+
9
+ def generate
10
+ Array.new(25) { @letters.sample }
11
+ end
12
+ end
13
+ 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,16 @@
1
+ module EulersDayOff
2
+ class WordList
3
+
4
+ def initialize
5
+ @data = []
6
+ end
7
+
8
+ def insert(element)
9
+ @data << element
10
+ end
11
+
12
+ def include?(element)
13
+ @data.include?(element)
14
+ end
15
+ end
16
+ 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
@@ -0,0 +1,3 @@
1
+ module EulersDayOff
2
+ VERSION = "0.1.0"
3
+ end