wordl-solver 1.2.1 → 1.3.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 +33 -30
- data/lib/wordl_solver_interface.rb +19 -15
- data/wordl-solver.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb3bf465211db353a6705e7a34a9678ab1c054e02fc8ee99c6420577705b8a09
|
4
|
+
data.tar.gz: 90e1a0ccec7e76c4c4e9609f8e55a858c557b7db48d73658ec0f3c8acb59f3cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7056a94cb5ad3f64cd8bbef26ae67e5bc72a7f85df20ad5084ef49e7a8f882236cb6fd6c97de30ee67f338035b14b5176838a74ac09bc473d8c5de46e33ff23b
|
7
|
+
data.tar.gz: b549d2effd15ae76b8910efaba4912d3f2f2974c335a2b5d5e99f08bcf79433f6256d2da37ce02f3e5ce57019e282d88a0caf185f05eb2ac135ce7831b1931b2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/wordl_solver.rb
CHANGED
@@ -11,45 +11,48 @@ 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.any? { |letter| word.include?(letter) }
|
55
|
+
end
|
53
56
|
end
|
54
57
|
end
|
55
58
|
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.3.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.3.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-06-16"
|
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]
|
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.3.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-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|