wordl-solver 0.2.1 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +18 -20
- data/VERSION +1 -1
- data/lib/wordl_solver.rb +137 -0
- data/wordl-solver.gemspec +4 -4
- metadata +3 -3
- data/lib/wordl-solver.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c953f3a69eea327f2201cc9ece27658ef958970737d557caf0a8b92d7b4ef9bf
|
4
|
+
data.tar.gz: cf9e13b893eb0b03de435080dc0d7af50a19903614fc2b20e34dd614f773bf25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d08f9d52496afc64c5bafdd81ea55318d13049e9fe2053ff1a416f550bfffdb00cadd2639b96a1800e0bb9205d1176c604098bbd00178a3ab9575e4353f9520
|
7
|
+
data.tar.gz: 6dd04312d1638daca91c843a6beae75e300e3b666c11e4e7a8df07f65b99b9537bef3b7a4e75d0cea9679bd4a2df72788f83f8632adc6466d27f8763131f30b9
|
data/Rakefile
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
5
3
|
begin
|
6
4
|
Bundler.setup(:default, :development)
|
7
5
|
rescue Bundler::BundlerError => e
|
8
|
-
|
9
|
-
|
6
|
+
warn e.message
|
7
|
+
warn "Run `bundle install` to install missing gems"
|
10
8
|
exit e.status_code
|
11
9
|
end
|
12
|
-
require
|
13
|
-
require
|
10
|
+
require "rake"
|
11
|
+
require "juwelier"
|
14
12
|
Juwelier::Tasks.new do |gem|
|
15
13
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
16
14
|
gem.name = "wordl-solver"
|
@@ -22,30 +20,30 @@ Juwelier::Tasks.new do |gem|
|
|
22
20
|
gem.authors = ["george kosmopoulos"]
|
23
21
|
gem.files.include "lib/*"
|
24
22
|
# dependencies defined in Gemfile
|
25
|
-
gem.executables = [
|
23
|
+
gem.executables = ["wordl-solver"]
|
26
24
|
end
|
27
25
|
Juwelier::RubygemsDotOrgTasks.new
|
28
|
-
require
|
26
|
+
require "rake/testtask"
|
29
27
|
Rake::TestTask.new(:test) do |test|
|
30
|
-
test.libs <<
|
31
|
-
test.pattern =
|
28
|
+
test.libs << "lib" << "test"
|
29
|
+
test.pattern = "test/**/test_*.rb"
|
32
30
|
test.verbose = true
|
33
31
|
end
|
34
32
|
|
35
33
|
desc "Code coverage detail"
|
36
34
|
task :simplecov do
|
37
|
-
ENV[
|
38
|
-
Rake::Task[
|
35
|
+
ENV["COVERAGE"] = "true"
|
36
|
+
Rake::Task["test"].execute
|
39
37
|
end
|
40
38
|
|
41
|
-
task :
|
39
|
+
task default: :test
|
42
40
|
|
43
|
-
require
|
41
|
+
require "rdoc/task"
|
44
42
|
Rake::RDocTask.new do |rdoc|
|
45
|
-
version = File.exist?(
|
43
|
+
version = File.exist?("VERSION") ? File.read("VERSION") : ""
|
46
44
|
|
47
|
-
rdoc.rdoc_dir =
|
45
|
+
rdoc.rdoc_dir = "rdoc"
|
48
46
|
rdoc.title = "wordl-solver #{version}"
|
49
|
-
rdoc.rdoc_files.include(
|
50
|
-
rdoc.rdoc_files.include(
|
47
|
+
rdoc.rdoc_files.include("README*")
|
48
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
51
49
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/lib/wordl_solver.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
FILE_PATH = File.join(File.dirname(__FILE__), '5_words.csv')
|
7
|
+
|
8
|
+
LETTER_WORDS = [].freeze
|
9
|
+
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].reverse.freeze
|
10
|
+
|
11
|
+
CSV.foreach(FILE_PATH) do |row|
|
12
|
+
LETTER_WORDS << row[0]
|
13
|
+
end
|
14
|
+
|
15
|
+
class WordlSolver
|
16
|
+
def initialize
|
17
|
+
@yellows = {
|
18
|
+
0 => [],
|
19
|
+
1 => [],
|
20
|
+
2 => [],
|
21
|
+
3 => [],
|
22
|
+
4 => []
|
23
|
+
}
|
24
|
+
@greys = []
|
25
|
+
@greens = {
|
26
|
+
0 => nil,
|
27
|
+
1 => nil,
|
28
|
+
2 => nil,
|
29
|
+
3 => nil,
|
30
|
+
4 => nil
|
31
|
+
}
|
32
|
+
@possible_words = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.run
|
36
|
+
WordlSolver.new.run
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
answer = ''
|
41
|
+
while answer != 'y'
|
42
|
+
ask_for_letters_and_colours
|
43
|
+
find_possible_words
|
44
|
+
present_possible_words
|
45
|
+
puts 'have you found it ? (y/n)'
|
46
|
+
answer = gets.chomp
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ask_for_letters_and_colours
|
53
|
+
puts 'Type in order color initial then the letter'
|
54
|
+
puts '(s for silver, y for yellow and g for green)'
|
55
|
+
5.times do |t|
|
56
|
+
puts @greens[t]
|
57
|
+
if @greens[t].nil?
|
58
|
+
puts "for position #{t + 1}"
|
59
|
+
letters = gets.chomp
|
60
|
+
while check_word_correct(letters)
|
61
|
+
puts "sorry, didn't catch that, try again:"
|
62
|
+
letters = gets.chomp
|
63
|
+
end
|
64
|
+
sort_letter_upon_color(letters, t)
|
65
|
+
else
|
66
|
+
puts "for position #{t + 1} this #{@greens[t]}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def sort_letter_upon_color(letters, t)
|
72
|
+
case letters[0]
|
73
|
+
when 's'
|
74
|
+
@greys << letters[1]
|
75
|
+
when 'y'
|
76
|
+
@yellows[t] << letters[1]
|
77
|
+
else
|
78
|
+
@greens[t] = letters[1]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def find_possible_words
|
83
|
+
filter_greens
|
84
|
+
filter_yellows
|
85
|
+
filter_greys
|
86
|
+
end
|
87
|
+
|
88
|
+
def present_possible_words
|
89
|
+
puts 'here are the existing words'
|
90
|
+
hash_word_frequency = {}
|
91
|
+
@possible_words.each do |word|
|
92
|
+
count = 0
|
93
|
+
word.chars.uniq.each do |char|
|
94
|
+
count += LETTER_FRENQUENCY.index(char)
|
95
|
+
end
|
96
|
+
hash_word_frequency[word] = count
|
97
|
+
end
|
98
|
+
hash_word_frequency = hash_word_frequency.sort_by { |_k, v| v }
|
99
|
+
hash_word_frequency.last(30).each do |word, count|
|
100
|
+
p "#{word} : #{count}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def filter_greens
|
105
|
+
@possible_words = (@possible_words.empty? ? LETTER_WORDS : @possible_words).select do |word|
|
106
|
+
put_in = true
|
107
|
+
@greens.each do |key, value|
|
108
|
+
next if value.nil?
|
109
|
+
|
110
|
+
put_in = false unless word[key] == value
|
111
|
+
end
|
112
|
+
put_in
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def filter_yellows
|
117
|
+
yellow_letters = @yellows.values.flatten.uniq
|
118
|
+
@possible_words.select! do |word|
|
119
|
+
possible = true
|
120
|
+
word.chars.each_with_index do |letter, index|
|
121
|
+
possible = false if @yellows[index].include?(letter)
|
122
|
+
end
|
123
|
+
possible = false unless yellow_letters.all? { |letter| word.include?(letter) }
|
124
|
+
possible
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def filter_greys
|
129
|
+
@possible_words.reject! do |word|
|
130
|
+
@greys.any? { |letter| word.include?(letter) }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def check_word_correct(letters)
|
135
|
+
letters.length != 2 || !%w[s y g].include?(letters[0])
|
136
|
+
end
|
137
|
+
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 0.2.
|
5
|
+
# stub: wordl-solver 0.2.4 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.4"
|
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-28"
|
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]
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"VERSION",
|
30
30
|
"bin/wordl-solver",
|
31
31
|
"lib/5_words.csv",
|
32
|
-
"lib/
|
32
|
+
"lib/wordl_solver.rb",
|
33
33
|
"wordl-solver.gemspec"
|
34
34
|
]
|
35
35
|
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: 0.2.
|
4
|
+
version: 0.2.4
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
- VERSION
|
102
102
|
- bin/wordl-solver
|
103
103
|
- lib/5_words.csv
|
104
|
-
- lib/
|
104
|
+
- lib/wordl_solver.rb
|
105
105
|
- wordl-solver.gemspec
|
106
106
|
homepage: http://github.com/gkosmo/wordl-solver
|
107
107
|
licenses:
|
data/lib/wordl-solver.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require "csv"
|
2
|
-
require "fileutils"
|
3
|
-
|
4
|
-
FILE_PATH = File.join( File.dirname(__FILE__), '5_words.csv')
|
5
|
-
|
6
|
-
LETTER_WORDS = []
|
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)
|
8
|
-
|
9
|
-
CSV.foreach(FILE_PATH) do |row|
|
10
|
-
LETTER_WORDS << row[0]
|
11
|
-
end
|
12
|
-
|
13
|
-
class WordlSolver
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@yellows = {
|
17
|
-
0 => [],
|
18
|
-
1 => [],
|
19
|
-
2 => [],
|
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
|
-
end
|
32
|
-
|
33
|
-
def self.run
|
34
|
-
WordlSolver.new.run
|
35
|
-
end
|
36
|
-
|
37
|
-
def run
|
38
|
-
answer = ""
|
39
|
-
while answer != "y"
|
40
|
-
ask_for_letters_and_colours
|
41
|
-
find_possible_words
|
42
|
-
puts "have you found it ? (y/n)"
|
43
|
-
answer = gets.chomp
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def ask_for_letters_and_colours
|
50
|
-
puts "Type in order color initial then the letter"
|
51
|
-
puts "(s for silver, y for yellow and g for green)"
|
52
|
-
5.times do |t|
|
53
|
-
puts @greens[t]
|
54
|
-
if @greens[t].nil?
|
55
|
-
puts "for position #{t + 1}"
|
56
|
-
letters = gets.chomp
|
57
|
-
while check_word_correct(letters)
|
58
|
-
puts "sorry, didn't catch that, try again:"
|
59
|
-
letters = gets.chomp
|
60
|
-
end
|
61
|
-
if letters[0] == 's'
|
62
|
-
@greys << letters[1]
|
63
|
-
elsif letters[0] == 'y'
|
64
|
-
@yellows[t] << letters[1]
|
65
|
-
else
|
66
|
-
@greens[t] = letters[1]
|
67
|
-
end
|
68
|
-
else
|
69
|
-
puts "for position #{t + 1} this #{@greens[t]}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
return [@greens, @yellows, @greys]
|
73
|
-
end
|
74
|
-
|
75
|
-
def find_possible_words
|
76
|
-
possible_words = []
|
77
|
-
LETTER_WORDS.each do |word|
|
78
|
-
put_in = true
|
79
|
-
@greens.each do |key, value|
|
80
|
-
next if value == nil
|
81
|
-
put_in = false unless word[key] == value
|
82
|
-
end
|
83
|
-
possible_words << word if put_in
|
84
|
-
end
|
85
|
-
possible_words.select do |word|
|
86
|
-
possible = true
|
87
|
-
word.chars.each_with_index do |letter, index|
|
88
|
-
possible = false if @yellows[index].include?(letter)
|
89
|
-
end
|
90
|
-
possible
|
91
|
-
end
|
92
|
-
possible_words = possible_words.select do |word|
|
93
|
-
!@greys.any? { |letter| word.include?(letter) }
|
94
|
-
end
|
95
|
-
puts "here are the existing words"
|
96
|
-
hash_word_frequency = Hash.new()
|
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}"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def check_word_correct(letters)
|
111
|
-
letters.length != 2 || !%w[s y g].include?(letters[0])
|
112
|
-
end
|
113
|
-
end
|