wordl-solver 1.1.1 → 1.2.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 +12 -106
- data/lib/wordl_solver_interface.rb +102 -0
- data/wordl-solver.gemspec +4 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5226c1f55ef956b38c9036f7df851e6b2cc61f36dbbd12b0ddcf9fa2f9a55c98
|
4
|
+
data.tar.gz: c53683f2e603eb76b9fabc4e8a922a4321d424e1267167d8e7a5e8540271bc54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0af7c871a5a1950c4022c7f68ab3b08575e35225c363bca46693bc900113a885070fae5841e132827eaf239793cbc9a08bd03fc3f226abef49d0dda3fcc579bc
|
7
|
+
data.tar.gz: 073a5b53b0607f97f870aaa3703be98fe8f5c7b491dc739d37080f4eea6228273f2d2bc76c67c904924316afdc959e352dbc462553a26ecc0305ee8f06fbe53e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/wordl_solver.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "csv"
|
4
|
+
require "fileutils"
|
5
5
|
|
6
|
-
FILE_PATH = File.join(File.dirname(__FILE__),
|
6
|
+
FILE_PATH = File.join(File.dirname(__FILE__), "5_words.csv")
|
7
7
|
|
8
8
|
LETTER_WORDS = []
|
9
9
|
|
@@ -12,98 +12,18 @@ CSV.foreach(FILE_PATH) do |row|
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class WordlSolver
|
15
|
-
def
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
3 => [],
|
21
|
-
4 => []
|
22
|
-
}
|
23
|
-
@greys = []
|
24
|
-
@greens = {
|
25
|
-
0 => nil,
|
26
|
-
1 => nil,
|
27
|
-
2 => nil,
|
28
|
-
3 => nil,
|
29
|
-
4 => nil
|
30
|
-
}
|
31
|
-
@possible_words = []
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.run
|
35
|
-
WordlSolver.new.run
|
36
|
-
end
|
37
|
-
|
38
|
-
def run
|
39
|
-
answer = ''
|
40
|
-
while answer != 'y'
|
41
|
-
ask_for_letters_and_colours
|
42
|
-
find_possible_words
|
43
|
-
present_possible_words
|
44
|
-
puts 'have you found it ? (y/n)'
|
45
|
-
answer = gets.chomp
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def ask_for_letters_and_colours
|
52
|
-
puts 'Type in order color initial then the letter'
|
53
|
-
puts '(s for silver, y for yellow and g for green)'
|
54
|
-
5.times do |t|
|
55
|
-
puts @greens[t]
|
56
|
-
if @greens[t].nil?
|
57
|
-
puts "for position #{t + 1}"
|
58
|
-
letters = gets.chomp
|
59
|
-
while check_word_correct(letters)
|
60
|
-
puts "sorry, didn't catch that, try again:"
|
61
|
-
letters = gets.chomp
|
62
|
-
end
|
63
|
-
sort_letter_upon_color(letters, t)
|
64
|
-
else
|
65
|
-
puts "for position #{t + 1} this #{@greens[t]}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def sort_letter_upon_color(letters, t)
|
71
|
-
case letters[0]
|
72
|
-
when 's'
|
73
|
-
@greys << letters[1]
|
74
|
-
when 'y'
|
75
|
-
@yellows[t] << letters[1]
|
76
|
-
else
|
77
|
-
@greens[t] = letters[1]
|
78
|
-
end
|
79
|
-
@greys.reject! { |letter| @greens.include?(letter) || @yellows.values.flatten.include?(letter) }
|
80
|
-
end
|
81
|
-
|
82
|
-
def find_possible_words
|
83
|
-
@possible_words = @possible_words.empty? ? LETTER_WORDS : @possible_words
|
15
|
+
def self.find_possible_words(greys, greens, yellows)
|
16
|
+
@greys = greys
|
17
|
+
@greens = greens
|
18
|
+
@yellows = yellows
|
19
|
+
@possible_words = @possible_words.nil? || @possible_words.empty? ? LETTER_WORDS : @possible_words
|
84
20
|
filter_greens
|
85
21
|
filter_yellows
|
86
22
|
filter_greys
|
23
|
+
@possible_words
|
87
24
|
end
|
88
25
|
|
89
|
-
def
|
90
|
-
puts 'here are the existing words'
|
91
|
-
hash_word_frequency = {}
|
92
|
-
set_letters_frequencies
|
93
|
-
@possible_words.each do |word|
|
94
|
-
count = 0
|
95
|
-
word.chars.uniq.each do |char|
|
96
|
-
count += @frenquencies[char]
|
97
|
-
end
|
98
|
-
hash_word_frequency[word] = count
|
99
|
-
end
|
100
|
-
hash_word_frequency = hash_word_frequency.sort_by { |_k, v| v }
|
101
|
-
hash_word_frequency.each do |word, count|
|
102
|
-
p "#{word} : #{count}"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def filter_greens
|
26
|
+
def self.filter_greens
|
107
27
|
@possible_words.select! do |word|
|
108
28
|
put_in = true
|
109
29
|
@greens.each do |key, value|
|
@@ -115,7 +35,7 @@ class WordlSolver
|
|
115
35
|
end
|
116
36
|
end
|
117
37
|
|
118
|
-
def filter_yellows
|
38
|
+
def self.filter_yellows
|
119
39
|
yellow_letters = @yellows.values.flatten.uniq
|
120
40
|
@possible_words.select! do |word|
|
121
41
|
possible = true
|
@@ -127,23 +47,9 @@ class WordlSolver
|
|
127
47
|
end
|
128
48
|
end
|
129
49
|
|
130
|
-
def filter_greys
|
50
|
+
def self.filter_greys
|
131
51
|
@possible_words.reject! do |word|
|
132
52
|
@greys.any? { |letter| word.include?(letter) }
|
133
53
|
end
|
134
54
|
end
|
135
|
-
|
136
|
-
def check_word_correct(letters)
|
137
|
-
letters.length != 2 || !%w[s y g].include?(letters[0])
|
138
|
-
end
|
139
|
-
|
140
|
-
def set_letters_frequencies
|
141
|
-
@frenquencies = {}
|
142
|
-
@possible_words.each do |word|
|
143
|
-
word.chars.each do |letter|
|
144
|
-
@frenquencies[letter] = 0 if @frenquencies[letter].nil?
|
145
|
-
@frenquencies[letter] += 1
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
55
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative "wordl_solver"
|
2
|
+
class WordlSolverInterface
|
3
|
+
def self.run
|
4
|
+
new.run
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@yellows = {
|
9
|
+
0 => [],
|
10
|
+
1 => [],
|
11
|
+
2 => [],
|
12
|
+
3 => [],
|
13
|
+
4 => []
|
14
|
+
}
|
15
|
+
@greys = []
|
16
|
+
@greens = {
|
17
|
+
0 => nil,
|
18
|
+
1 => nil,
|
19
|
+
2 => nil,
|
20
|
+
3 => nil,
|
21
|
+
4 => nil
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
answer = ""
|
27
|
+
while answer != "y"
|
28
|
+
ask_for_letters_and_colours
|
29
|
+
@possible_words = WordlSolver.find_possible_words(@greys, @greens, @yellows)
|
30
|
+
present_possible_words
|
31
|
+
puts "have you found it ? (y/n)"
|
32
|
+
answer = gets.chomp
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def sort_letter_upon_color(letters, t)
|
39
|
+
case letters[0]
|
40
|
+
when "s"
|
41
|
+
@greys << letters[1]
|
42
|
+
when "y"
|
43
|
+
@yellows[t] << letters[1]
|
44
|
+
else
|
45
|
+
@greens[t] = letters[1]
|
46
|
+
end
|
47
|
+
@greys.reject! { |letter| @greens.include?(letter) || @yellows.values.flatten.include?(letter) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def ask_for_letters_and_colours
|
51
|
+
puts "Type two letters attached. First the initial of the color you have"
|
52
|
+
puts "(s for silver (grey), y for yellow and g for green)"
|
53
|
+
puts "and then the letter that was tried."
|
54
|
+
puts "For example, if you have tried and arose and you get grey for a"
|
55
|
+
puts "You'd type, after being prompted for the first position: sa "
|
56
|
+
5.times do |t|
|
57
|
+
puts @greens[t]
|
58
|
+
if @greens[t].nil?
|
59
|
+
puts "for position #{t + 1}"
|
60
|
+
letters = gets.chomp
|
61
|
+
while check_word_correct(letters)
|
62
|
+
puts "sorry, didn't catch that, try again:"
|
63
|
+
letters = gets.chomp
|
64
|
+
end
|
65
|
+
sort_letter_upon_color(letters, t)
|
66
|
+
else
|
67
|
+
puts "for position #{t + 1} this #{@greens[t]}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def present_possible_words
|
73
|
+
puts "here are the existing words"
|
74
|
+
hash_word_frequency = {}
|
75
|
+
set_letters_frequencies
|
76
|
+
@possible_words.each do |word|
|
77
|
+
count = 0
|
78
|
+
word.chars.uniq.each do |char|
|
79
|
+
count += @frenquencies[char]
|
80
|
+
end
|
81
|
+
hash_word_frequency[word] = count
|
82
|
+
end
|
83
|
+
hash_word_frequency = hash_word_frequency.sort_by { |_k, v| v }
|
84
|
+
hash_word_frequency.each do |word, count|
|
85
|
+
p "#{word} : #{count}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def check_word_correct(letters)
|
90
|
+
letters.length != 2 || !%w[s y g].include?(letters[0])
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_letters_frequencies
|
94
|
+
@frenquencies = {}
|
95
|
+
@possible_words.each do |word|
|
96
|
+
word.chars.each do |letter|
|
97
|
+
@frenquencies[letter] = 0 if @frenquencies[letter].nil?
|
98
|
+
@frenquencies[letter] += 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
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.2.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.2.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-05-
|
14
|
+
s.date = "2022-05-31"
|
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]
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"bin/wordl-solver",
|
31
31
|
"lib/5_words.csv",
|
32
32
|
"lib/wordl_solver.rb",
|
33
|
+
"lib/wordl_solver_interface.rb",
|
33
34
|
"wordl-solver.gemspec"
|
34
35
|
]
|
35
36
|
s.homepage = "http://github.com/gkosmo/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.2.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-05-
|
11
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- bin/wordl-solver
|
103
103
|
- lib/5_words.csv
|
104
104
|
- lib/wordl_solver.rb
|
105
|
+
- lib/wordl_solver_interface.rb
|
105
106
|
- wordl-solver.gemspec
|
106
107
|
homepage: http://github.com/gkosmo/wordl-solver
|
107
108
|
licenses:
|