wordl-solver 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,106 +0,0 @@
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 |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)
62
- else
63
- puts "for position #{position + 1} this #{@greens[position]}"
64
- end
65
- end
66
- end
67
-
68
- def present_possible_words
69
- puts "here are the existing words"
70
- hash_word_frequency = {}
71
- set_letters_frequencies
72
- @possible_words.each do |word|
73
- count = 0
74
- word.chars.uniq.each do |char|
75
- count += @frenquencies[char]
76
- end
77
- hash_word_frequency[word] = count
78
- end
79
- hash_word_frequency = hash_word_frequency.sort_by { |_k, v| v }
80
- hash_word_frequency.each do |word, count|
81
- p "#{word} : #{count}"
82
- end
83
- end
84
-
85
- def word_is_correct?(letters)
86
- letters.length == 2 && %w[s y g].include?(letters[0])
87
- end
88
-
89
- def set_letters_frequencies
90
- @frenquencies = Hash.new(0)
91
- @possible_words.each do |word|
92
- word.chars.each do |letter|
93
- @frenquencies[letter] += 1
94
- end
95
- end
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
106
- end
data/wordl-solver.gemspec DELETED
@@ -1,59 +0,0 @@
1
- # Generated by juwelier
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: wordl-solver 1.4.0 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "wordl-solver".freeze
9
- s.version = "1.4.0"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib".freeze]
13
- s.authors = ["george kosmopoulos".freeze]
14
- s.date = "2022-12-24"
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
- s.email = "gkosmo1@hotmail.com".freeze
17
- s.executables = ["wordl-solver".freeze]
18
- s.extra_rdoc_files = [
19
- "LICENSE.txt",
20
- "README.rdoc"
21
- ]
22
- s.files = [
23
- ".document",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.rdoc",
28
- "Rakefile",
29
- "VERSION",
30
- "bin/wordl-solver",
31
- "lib/5_words.csv",
32
- "lib/wordl_solver.rb",
33
- "lib/wordl_solver_interface.rb",
34
- "wordl-solver.gemspec"
35
- ]
36
- s.homepage = "http://github.com/gkosmo/wordl-solver".freeze
37
- s.licenses = ["MIT".freeze]
38
- s.rubygems_version = "3.3.7".freeze
39
- s.summary = "This gem solves wordl puzzles.".freeze
40
-
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 4
43
- end
44
-
45
- if s.respond_to? :add_runtime_dependency then
46
- s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
47
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
48
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
49
- s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
50
- s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
51
- else
52
- s.add_dependency(%q<shoulda>.freeze, [">= 0"])
53
- s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
54
- s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
55
- s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
56
- s.add_dependency(%q<simplecov>.freeze, [">= 0"])
57
- end
58
- end
59
-