jumble_solver 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/jumble_solver.gemspec +24 -0
- data/lib/jumble_solver.rb +2 -0
- data/lib/jumble_solver/jumble.rb +38 -0
- data/lib/jumble_solver/version.rb +3 -0
- data/spec/jumble_solver_spec.rb +34 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzMzOTAzYTc1MDAzZjI5MjEwZGE4NzFjYmFiY2NjMjA0MmRkMWFmOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTRkOGExNmYyOTliZTRhYTQ0ODAzZWY3NTA5Y2Y2YmViYzBjMTRjZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDE2N2Y3OGYwNjgxN2FjNmFiNDQ2ZWVmNjFkM2JhMWEwYmE3OGQ1ZGM4OWU2
|
10
|
+
ODJkZDk0MjkxMWZkMjQwOTRkYmVmYTE0YzFlYTc5YmFmNjQ1ODRiYmI1ZmE2
|
11
|
+
ZTBhNmEwMGYxMmFjN2IwNmFmZWQyMzg5OTAxMDY5OWU3NWMwMmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGExYjNkNzdiZDlkOGIzZTgwZDQyYTU2MDBlMTBlMjEyY2NjZjg3Mzc5ZDk4
|
14
|
+
NzAxNWYwODM5YTU3NWE0ZmY2NWNhYzNjOGI1ZmE5OWUzODU5OTJjNDIxM2U0
|
15
|
+
NDBmZmQ1MDE2NzQwNjA2YzVmMTQwMTU0YzFmNzk3MGQ0MmFhNTg=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ramesh Jha
|
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,27 @@
|
|
1
|
+
# Jumble Solver
|
2
|
+
|
3
|
+
It's a ruby gem for solving jumble word puzzles.
|
4
|
+
|
5
|
+
It will return all the possible valid combination for the given word.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'jumble_solver'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jumble_solver
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
jumble_solver.solve("rat")
|
24
|
+
=> ["art", "rat", "tar"]
|
25
|
+
|
26
|
+
### Website
|
27
|
+
http://jumblesolver.me
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jumble_solver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jumble_solver"
|
8
|
+
spec.version = JumbleSolver::VERSION
|
9
|
+
spec.authors = ["Ramesh Jha"]
|
10
|
+
spec.email = ["ramesh@rameshjha.com"]
|
11
|
+
spec.description = %q{It can be used for solving jumble word puzzles}
|
12
|
+
spec.summary = %q{A jumble solver}
|
13
|
+
spec.homepage = "https://github.com/rkjha/jumble_solver"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module JumbleSolver
|
2
|
+
class Jumble
|
3
|
+
def initialize
|
4
|
+
# loading the dictionary
|
5
|
+
@word_list = load_dictionary
|
6
|
+
end
|
7
|
+
|
8
|
+
def load_dictionary
|
9
|
+
wl = []
|
10
|
+
file = File.open("/usr/share/dict/words", 'r')
|
11
|
+
file.each_line do |line|
|
12
|
+
wl.push(line.chomp)
|
13
|
+
end
|
14
|
+
wl
|
15
|
+
end
|
16
|
+
|
17
|
+
def solve letters
|
18
|
+
valid_words = []
|
19
|
+
letters = letters.downcase.split(//)
|
20
|
+
no_of_letters = letters.length
|
21
|
+
@word_list.each do |word|
|
22
|
+
next unless word.length == no_of_letters
|
23
|
+
word_copy = word
|
24
|
+
word = word.split(//)
|
25
|
+
letters.each do |letter|
|
26
|
+
if word.include? letter
|
27
|
+
word.delete_at word.index(letter)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
if word.length == 0
|
31
|
+
valid_words.push(word_copy)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
valid_words
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "jumble_solver"
|
2
|
+
|
3
|
+
describe "jumble solver" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@j = JumbleSolver::Jumble.new()
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Solvable words" do
|
10
|
+
it "should return the array of valid words" do
|
11
|
+
valid_words = @j.solve("art")
|
12
|
+
expect(valid_words).to be_kind_of(Array)
|
13
|
+
expect(valid_words).to_not be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Unsolvable words" do
|
18
|
+
it "should return an empty array" do
|
19
|
+
valid_words = @j.solve("huahua")
|
20
|
+
expect(valid_words).to be_kind_of(Array)
|
21
|
+
expect(valid_words).to be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "Accuracy of the result" do
|
26
|
+
it "should return correct words" do
|
27
|
+
valid_words = @j.solve("rat")
|
28
|
+
expect(valid_words).to include("art")
|
29
|
+
expect(valid_words).to include("rat")
|
30
|
+
expect(valid_words).to include("tar")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jumble_solver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramesh Jha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
description: It can be used for solving jumble word puzzles
|
56
|
+
email:
|
57
|
+
- ramesh@rameshjha.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- jumble_solver.gemspec
|
69
|
+
- lib/jumble_solver.rb
|
70
|
+
- lib/jumble_solver/jumble.rb
|
71
|
+
- lib/jumble_solver/version.rb
|
72
|
+
- spec/jumble_solver_spec.rb
|
73
|
+
homepage: https://github.com/rkjha/jumble_solver
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.1.9
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A jumble solver
|
97
|
+
test_files:
|
98
|
+
- spec/jumble_solver_spec.rb
|