wordl-solver 1.2.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/wordl_solver.rb +39 -30
- data/lib/wordl_solver_interface.rb +19 -15
- data/wordl-solver.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3efe4e2edfac6ae7fddccd6b38b2fe803fbbc35c4e3ae01cbbb609c611a40124
|
4
|
+
data.tar.gz: 5d99360b9bdacf90248bb7c6b6a16a944f681b93baa33daa4aca7486b2c17b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8765927089a057472a1545f754bcaef4a715475ca29fc38afd71a0e44bb58d9248b8abd470f1a538b1ce70b535cb9d9e4b862da4d6826bb9f446132765457a13
|
7
|
+
data.tar.gz: 8cf74de88be9641c8f486ae84b8448273d64e1d5a60c2e2ffbd313c1e991288627d9c12503df53724b6c40cc06d8b0d42a778a35f5d8ef410c040b5ff4f47a0d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/lib/wordl_solver.rb
CHANGED
@@ -11,45 +11,54 @@ CSV.foreach(FILE_PATH) do |row|
|
|
11
11
|
LETTER_WORDS << row[0]
|
12
12
|
end
|
13
13
|
|
14
|
+
# The Class WordlSolver is a class that contains the methods to solve the wordl puzzle.
|
14
15
|
class WordlSolver
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
class << self
|
17
|
+
def find_possible_words(greys, greens, yellows)
|
18
|
+
@greys = greys
|
19
|
+
@greens = greens
|
20
|
+
@yellows = yellows
|
21
|
+
@possible_words = @possible_words.nil? || @possible_words.empty? ? LETTER_WORDS : @possible_words
|
22
|
+
filter_greens
|
23
|
+
filter_yellows
|
24
|
+
filter_greys
|
25
|
+
@possible_words
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def filter_greens
|
29
|
+
@possible_words.select! do |word|
|
30
|
+
put_in = true
|
31
|
+
@greens.each do |key, value|
|
32
|
+
next if value.nil?
|
31
33
|
|
32
|
-
|
34
|
+
put_in = false unless word[key] == value
|
35
|
+
end
|
36
|
+
put_in
|
33
37
|
end
|
34
|
-
put_in
|
35
38
|
end
|
36
|
-
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def filter_yellows
|
41
|
+
yellow_letters = @yellows.values.flatten.uniq
|
42
|
+
@possible_words.select! do |word|
|
43
|
+
possible = true
|
44
|
+
word.chars.each_with_index do |letter, index|
|
45
|
+
possible = false if @yellows[index].include?(letter)
|
46
|
+
end
|
47
|
+
possible = false unless yellow_letters.all? { |letter| word.include?(letter) }
|
48
|
+
possible
|
44
49
|
end
|
45
|
-
possible = false unless yellow_letters.all? { |letter| word.include?(letter) }
|
46
|
-
possible
|
47
50
|
end
|
48
|
-
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
def filter_greys
|
53
|
+
@possible_words.reject! do |word|
|
54
|
+
@greys.each do |letter|
|
55
|
+
if @greens.values.include?(letter)
|
56
|
+
word.count(letter) > 1
|
57
|
+
else
|
58
|
+
word.include?(letter)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
55
64
|
end
|
@@ -53,18 +53,14 @@ class WordlSolverInterface
|
|
53
53
|
puts "and then the letter that was tried."
|
54
54
|
puts "For example, if you have tried and arose and you get grey for a"
|
55
55
|
puts "You'd type, after being prompted for the first position: sa "
|
56
|
-
5.times do |
|
57
|
-
puts @greens[
|
58
|
-
if @greens[
|
59
|
-
puts "for position #{
|
60
|
-
letters =
|
61
|
-
|
62
|
-
puts "sorry, didn't catch that, try again:"
|
63
|
-
letters = gets.chomp
|
64
|
-
end
|
65
|
-
sort_letter_upon_color(letters, t)
|
56
|
+
5.times do |position|
|
57
|
+
puts @greens[position]
|
58
|
+
if @greens[position].nil?
|
59
|
+
puts "for position #{position + 1}"
|
60
|
+
letters = retrieve_input_letters
|
61
|
+
sort_letter_upon_color(letters, position)
|
66
62
|
else
|
67
|
-
puts "for position #{
|
63
|
+
puts "for position #{position + 1} this #{@greens[position]}"
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
@@ -86,17 +82,25 @@ class WordlSolverInterface
|
|
86
82
|
end
|
87
83
|
end
|
88
84
|
|
89
|
-
def
|
90
|
-
letters.length
|
85
|
+
def word_is_correct?(letters)
|
86
|
+
letters.length == 2 && %w[s y g].include?(letters[0])
|
91
87
|
end
|
92
88
|
|
93
89
|
def set_letters_frequencies
|
94
|
-
@frenquencies =
|
90
|
+
@frenquencies = Hash.new(0)
|
95
91
|
@possible_words.each do |word|
|
96
92
|
word.chars.each do |letter|
|
97
|
-
@frenquencies[letter] = 0 if @frenquencies[letter].nil?
|
98
93
|
@frenquencies[letter] += 1
|
99
94
|
end
|
100
95
|
end
|
101
96
|
end
|
97
|
+
|
98
|
+
def retrieve_input_letters
|
99
|
+
letters = gets.chomp
|
100
|
+
until word_is_correct?(letters)
|
101
|
+
puts "sorry, didn't catch that, try again:"
|
102
|
+
letters = gets.chomp
|
103
|
+
end
|
104
|
+
letters
|
105
|
+
end
|
102
106
|
end
|
data/wordl-solver.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: wordl-solver 1.
|
5
|
+
# stub: wordl-solver 1.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "wordl-solver".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["george kosmopoulos".freeze]
|
14
|
-
s.date = "2022-
|
14
|
+
s.date = "2022-12-24"
|
15
15
|
s.description = "This gem helps you solve wordl puzzles. It does so by asking you for the letters position you know, the letters you know exists and the ones you know don't exists. It then proposes words depending on how good they are by weighting the letters by their frequency in the english language.".freeze
|
16
16
|
s.email = "gkosmo1@hotmail.com".freeze
|
17
17
|
s.executables = ["wordl-solver".freeze]
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
]
|
36
36
|
s.homepage = "http://github.com/gkosmo/wordl-solver".freeze
|
37
37
|
s.licenses = ["MIT".freeze]
|
38
|
-
s.rubygems_version = "3.3.
|
38
|
+
s.rubygems_version = "3.3.7".freeze
|
39
39
|
s.summary = "This gem solves wordl puzzles.".freeze
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordl-solver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- george kosmopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.3.
|
126
|
+
rubygems_version: 3.3.7
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: This gem solves wordl puzzles.
|