wordl-solver 1.0.0 → 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/README.rdoc +10 -0
- data/VERSION +1 -1
- data/lib/wordl_solver.rb +12 -105
- 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/README.rdoc
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
Description goes here.
|
4
4
|
|
5
|
+
This is a tool I've built to help me solve wordle.
|
6
|
+
It does so by providing all the 5 letter words, ordering them by the frequency of the letters and filter them depending on the the colours.
|
7
|
+
|
8
|
+
|
9
|
+
** Still To DO
|
10
|
+
|
11
|
+
- have the logic for when a letter appear twice or not
|
12
|
+
- allow to correct the inputs
|
13
|
+
- clean the code a bit more
|
14
|
+
|
5
15
|
== Contributing to wordl-solver
|
6
16
|
|
7
17
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
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,97 +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
|
-
end
|
80
|
-
|
81
|
-
def find_possible_words
|
82
|
-
@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
|
83
20
|
filter_greens
|
84
21
|
filter_yellows
|
85
22
|
filter_greys
|
23
|
+
@possible_words
|
86
24
|
end
|
87
25
|
|
88
|
-
def
|
89
|
-
puts 'here are the existing words'
|
90
|
-
hash_word_frequency = {}
|
91
|
-
set_letters_frequencies
|
92
|
-
@possible_words.each do |word|
|
93
|
-
count = 0
|
94
|
-
word.chars.uniq.each do |char|
|
95
|
-
count += @frenquencies[char]
|
96
|
-
end
|
97
|
-
hash_word_frequency[word] = count
|
98
|
-
end
|
99
|
-
hash_word_frequency = hash_word_frequency.sort_by { |_k, v| v }
|
100
|
-
hash_word_frequency.last(30).each do |word, count|
|
101
|
-
p "#{word} : #{count}"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def filter_greens
|
26
|
+
def self.filter_greens
|
106
27
|
@possible_words.select! do |word|
|
107
28
|
put_in = true
|
108
29
|
@greens.each do |key, value|
|
@@ -114,7 +35,7 @@ class WordlSolver
|
|
114
35
|
end
|
115
36
|
end
|
116
37
|
|
117
|
-
def filter_yellows
|
38
|
+
def self.filter_yellows
|
118
39
|
yellow_letters = @yellows.values.flatten.uniq
|
119
40
|
@possible_words.select! do |word|
|
120
41
|
possible = true
|
@@ -126,23 +47,9 @@ class WordlSolver
|
|
126
47
|
end
|
127
48
|
end
|
128
49
|
|
129
|
-
def filter_greys
|
50
|
+
def self.filter_greys
|
130
51
|
@possible_words.reject! do |word|
|
131
52
|
@greys.any? { |letter| word.include?(letter) }
|
132
53
|
end
|
133
54
|
end
|
134
|
-
|
135
|
-
def check_word_correct(letters)
|
136
|
-
letters.length != 2 || !%w[s y g].include?(letters[0])
|
137
|
-
end
|
138
|
-
|
139
|
-
def set_letters_frequencies
|
140
|
-
@frenquencies = {}
|
141
|
-
@possible_words.each do |word|
|
142
|
-
word.chars.each do |letter|
|
143
|
-
@frenquencies[letter] = 0 if @frenquencies[letter].nil?
|
144
|
-
@frenquencies[letter] += 1
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
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:
|