wordl-solver 0.2.0 → 0.2.3
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/5_words.csv +5664 -12834
- data/lib/wordl-solver.rb +50 -32
- data/wordl-solver.gemspec +3 -3
- metadata +2 -2
data/lib/wordl-solver.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'csv'
|
2
|
+
require 'fileutils'
|
3
3
|
|
4
|
-
FILE_PATH = File.join(
|
4
|
+
FILE_PATH = File.join(File.dirname(__FILE__), '5_words.csv')
|
5
5
|
|
6
6
|
LETTER_WORDS = []
|
7
|
-
LETTER_FRENQUENCY = %w
|
7
|
+
LETTER_FRENQUENCY = %w[e t a o i n s h r d l c u m f w y g p b v k j x q z].freeze
|
8
8
|
|
9
9
|
CSV.foreach(FILE_PATH) do |row|
|
10
10
|
LETTER_WORDS << row[0]
|
11
11
|
end
|
12
12
|
|
13
13
|
class WordlSolver
|
14
|
-
|
15
14
|
def initialize
|
16
15
|
@yellows = {
|
17
16
|
0 => [],
|
@@ -28,6 +27,7 @@ class WordlSolver
|
|
28
27
|
3 => nil,
|
29
28
|
4 => nil
|
30
29
|
}
|
30
|
+
@possible_words = []
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.run
|
@@ -35,11 +35,12 @@ class WordlSolver
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def run
|
38
|
-
answer =
|
39
|
-
while answer !=
|
38
|
+
answer = ''
|
39
|
+
while answer != 'y'
|
40
40
|
ask_for_letters_and_colours
|
41
41
|
find_possible_words
|
42
|
-
|
42
|
+
present_possible_words
|
43
|
+
puts 'have you found it ? (y/n)'
|
43
44
|
answer = gets.chomp
|
44
45
|
end
|
45
46
|
end
|
@@ -47,8 +48,8 @@ class WordlSolver
|
|
47
48
|
private
|
48
49
|
|
49
50
|
def ask_for_letters_and_colours
|
50
|
-
puts
|
51
|
-
puts
|
51
|
+
puts 'Type in order color initial then the letter'
|
52
|
+
puts '(s for silver, y for yellow and g for green)'
|
52
53
|
5.times do |t|
|
53
54
|
puts @greens[t]
|
54
55
|
if @greens[t].nil?
|
@@ -69,41 +70,58 @@ class WordlSolver
|
|
69
70
|
puts "for position #{t + 1} this #{@greens[t]}"
|
70
71
|
end
|
71
72
|
end
|
72
|
-
|
73
|
+
[@greens, @yellows, @greys]
|
73
74
|
end
|
74
75
|
|
75
76
|
def find_possible_words
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
filter_greens
|
78
|
+
filter_yellows
|
79
|
+
filter_greys
|
80
|
+
end
|
81
|
+
|
82
|
+
def present_possible_words
|
83
|
+
puts 'here are the existing words'
|
84
|
+
hash_word_frequency = {}
|
85
|
+
@possible_words.each do |word|
|
86
|
+
count = 0
|
87
|
+
word.chars.each do |char|
|
88
|
+
count += LETTER_FRENQUENCY.index(char) + 2 * word.chars.count(char)
|
89
|
+
end
|
90
|
+
hash_word_frequency[word] = count
|
91
|
+
end
|
92
|
+
hash_word_frequency = hash_word_frequency.sort_by { |_k, v| v }
|
93
|
+
hash_word_frequency.first(30).each do |word, count|
|
94
|
+
p "#{word} : #{count}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def filter_greens
|
99
|
+
@possible_words = (@possible_words.empty? ? LETTER_WORDS : @possible_words).select do |word|
|
100
|
+
put_in = true
|
79
101
|
@greens.each do |key, value|
|
80
|
-
next if value
|
102
|
+
next if value.nil?
|
103
|
+
|
81
104
|
put_in = false unless word[key] == value
|
82
105
|
end
|
83
|
-
|
106
|
+
put_in
|
84
107
|
end
|
85
|
-
|
108
|
+
end
|
109
|
+
|
110
|
+
def filter_yellows
|
111
|
+
yellow_letters = @yellows.values.flatten.uniq
|
112
|
+
@possible_words.select! do |word|
|
86
113
|
possible = true
|
87
114
|
word.chars.each_with_index do |letter, index|
|
88
115
|
possible = false if @yellows[index].include?(letter)
|
89
116
|
end
|
117
|
+
possible = false unless yellow_letters.all? { |letter| word.include?(letter) }
|
90
118
|
possible
|
91
119
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
possible_words.each do |word|
|
98
|
-
count = 0
|
99
|
-
word.chars.each do |char|
|
100
|
-
count += LETTER_FRENQUENCY.index(char) + 2 * word.chars.count(char)
|
101
|
-
end
|
102
|
-
hash_word_frequency[word] = count
|
103
|
-
end
|
104
|
-
hash_word_frequency = hash_word_frequency.sort_by { |k, v| v }
|
105
|
-
hash_word_frequency.first(30).each do |word, count|
|
106
|
-
p "#{word} : #{count}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def filter_greys
|
123
|
+
@possible_words.reject! do |word|
|
124
|
+
@greys.any? { |letter| word.include?(letter) }
|
107
125
|
end
|
108
126
|
end
|
109
127
|
|
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 0.2.
|
5
|
+
# stub: wordl-solver 0.2.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "wordl-solver".freeze
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.3"
|
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-04-
|
14
|
+
s.date = "2022-04-22"
|
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: 0.2.
|
4
|
+
version: 0.2.3
|
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-04-
|
11
|
+
date: 2022-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|