danno_scrabble 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/Rakefile +8 -0
- data/bin/scrabble +4 -4
- data/lib/scrabble.rb +19 -18
- data/lib/word_list.txt +79339 -0
- data/test/test_scrabble.rb +29 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad2e25a1fd3c5295fa464c471d8ac753fe3a7a0
|
4
|
+
data.tar.gz: 0e2075abfe6b35de78abf23a7bd3b1ac4b999837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56cc7404a427024aec7c30669a2acdaa8964e54728fa753255c45dc62f5400b8afc5b96229f9daea670763fc661ed1d08ad0d89c423d8a7e3d44b67bf32ec510
|
7
|
+
data.tar.gz: 39ea0f3ba1bf4188928b61a5d5d4f467215b6f653c58f24474ff8a6f319bbdf9e34d9da628ca995631faabfb4564c51f7f4d32fc854cca218f0b8982f7d995b3
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
____ ___
|
2
|
+
| _ \ / _ \
|
3
|
+
| | | | | | | |
|
4
|
+
| |_| | | |_| |
|
5
|
+
|____/[] \ ___ /[]
|
6
|
+
|
7
|
+
Scrabble has long been used to play on words. For example, you have a set of letters, these letters then make various
|
8
|
+
combinations of words. In the rules of scrabble those various combinations of words are compared against a valid scrabble
|
9
|
+
dictionary to see if it is a valid answer. This provides a list of all possible valid answers based on the set of letters.
|
10
|
+
|
11
|
+
# Requirements
|
12
|
+
|
13
|
+
* Ruby -v 2.2.0+ # Use Rvm where possible `rvm install "version_number"`
|
14
|
+
* Install the clock `gem install danno_scrabble` or clone it from this repo.
|
15
|
+
|
16
|
+
# INFO
|
17
|
+
|
18
|
+
Sample Input
|
19
|
+
"asd"
|
20
|
+
|
21
|
+
Output for the Sample Input
|
22
|
+
["ad", "ads", "as", "da", "sad"]
|
23
|
+
|
24
|
+
# Using the Gem!
|
25
|
+
|
26
|
+
* `ruby -Ilib ./bin/scrabble {'scrabble'}` or `ruby -Ilib ./bin/scrabble {'asdfjkl'}` # if cloned
|
27
|
+
* `ruby -Ilib ~/.rvm/gems/ruby-2.2.3/gems/danno_scrabble_0.0.3/bin/scrabble {'scrabble'}` # if installed via `gem install`
|
data/Rakefile
ADDED
data/bin/scrabble
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'scrabble'
|
4
|
-
puts Scrabble.run_scrabble(ARGV[0])
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scrabble'
|
4
|
+
puts Scrabble.run_scrabble(ARGV[0])
|
data/lib/scrabble.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
###
|
3
|
-
# @author Dan Oberg <dan@cs1.com>
|
4
|
-
# @licence MIT
|
5
|
-
# @class Scrabble
|
6
|
-
# Useage: `ruby -Ilib ./bin/scrabble {'asdfjkl'}` or `ruby -Ilib ./bin/scrabble {'peodfor'}`
|
7
|
-
###
|
8
|
-
class Scrabble
|
9
|
-
###
|
10
|
-
# @param [String] run a list of letters against a text dictionary file for valid scrabble answers.
|
11
|
-
# @return [Array]
|
12
|
-
###
|
13
|
-
def self.run_scrabble(letters)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
###
|
3
|
+
# @author Dan Oberg <dan@cs1.com>
|
4
|
+
# @licence MIT
|
5
|
+
# @class Scrabble
|
6
|
+
# Useage: `ruby -Ilib ./bin/scrabble {'asdfjkl'}` or `ruby -Ilib ./bin/scrabble {'peodfor'}`
|
7
|
+
###
|
8
|
+
class Scrabble
|
9
|
+
###
|
10
|
+
# @param [String] run a list of letters against a text dictionary file for valid scrabble answers.
|
11
|
+
# @return [Array] returns possible valid results.
|
12
|
+
###
|
13
|
+
def self.run_scrabble(letters)
|
14
|
+
dictionary_path = File.join( File.dirname(__FILE__), 'word_list.txt' )
|
15
|
+
dictionary = File.readlines(dictionary_path).map(&:chomp)
|
16
|
+
possible = (2..letters.length).map{|n| letters.chars.to_a.permutation(n).to_a.map(&:join)}.flatten
|
17
|
+
dictionary & possible
|
18
|
+
end
|
19
|
+
end
|