wordl-solver 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58205da9e87e49dfa226d3feeb87cf0850174261a84cada730447615201b7e4c
4
- data.tar.gz: 5bcc73638f47aa8f4f6d42b6869ba868fcb77d2053cc0ff726cc93e7c89e14c5
3
+ metadata.gz: 0f326a634328a97eef7ad9e227edb9f8255108f451862c8a62384ad17b8b9985
4
+ data.tar.gz: e97864313b704202cd0e089f937c808fbe8dd7ab0a147a385fae127aad433674
5
5
  SHA512:
6
- metadata.gz: 512584fc0eaf9b9599304f62d3ef775c2fc925cdc87ce6993d08daa1f33bd52496e8ae3c9c67de61c7568575196ebfad8fd35a3e8523a80605c357b410df7634
7
- data.tar.gz: bf3e7c005fbdd07c1b20ed0940eabbc533c6aa58f78d773f760d2f4c1372b2aef041e23954746e5c0f2674858a9c1af81b8729ba6cc021de4979ddcad1f3eba4
6
+ metadata.gz: dd62d01accc322db7fbf2a18210e64ddf795beb806dadfae46bc0168a930a99cfce55527ec6488b5a978145cb34db949c4e82e4375e4981fabc832e593ecc507
7
+ data.tar.gz: 58e72e25b1f0c2efff9b76de6f92d99d1f27f669a8bd769cef8b006d5a7fd22f3b67d49f2c41223644a7eb2e1500cbe250faafafd815ed9efdbecb540d3bed56
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/lib/wordl-solver.rb CHANGED
@@ -11,7 +11,7 @@ CSV.foreach(FILE_PATH) do |row|
11
11
  end
12
12
 
13
13
  class WordlSolver
14
-
14
+
15
15
  def initialize
16
16
  @yellows = {
17
17
  0 => [],
@@ -28,6 +28,7 @@ class WordlSolver
28
28
  3 => nil,
29
29
  4 => nil
30
30
  }
31
+ @possible_words = []
31
32
  end
32
33
 
33
34
  def self.run
@@ -39,6 +40,7 @@ class WordlSolver
39
40
  while answer != "y"
40
41
  ask_for_letters_and_colours
41
42
  find_possible_words
43
+ present_possible_words
42
44
  puts "have you found it ? (y/n)"
43
45
  answer = gets.chomp
44
46
  end
@@ -73,28 +75,15 @@ class WordlSolver
73
75
  end
74
76
 
75
77
  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
78
+ filter_greens
79
+ filter_yellows
80
+ filter_greys
81
+ end
82
+
83
+ def present_possible_words
95
84
  puts "here are the existing words"
96
85
  hash_word_frequency = Hash.new()
97
- possible_words.each do |word|
86
+ @possible_words.each do |word|
98
87
  count = 0
99
88
  word.chars.each do |char|
100
89
  count += LETTER_FRENQUENCY.index(char) + 2 * word.chars.count(char)
@@ -107,6 +96,34 @@ class WordlSolver
107
96
  end
108
97
  end
109
98
 
99
+ def filter_greens
100
+ @possible_words = (@possible_words.empty? ? LETTER_WORDS : @possible_words).select do |word|
101
+ put_in = true
102
+ @greens.each do |key, value|
103
+ next if value.nil?
104
+
105
+ put_in = false unless word[key] == value
106
+ end
107
+ put_in
108
+ end
109
+ end
110
+
111
+ def filter_yellows
112
+ @possible_words.select! do |word|
113
+ possible = true
114
+ word.chars.each_with_index do |letter, index|
115
+ possible = false if @yellows[index].include?(letter)
116
+ end
117
+ possible
118
+ end
119
+ end
120
+
121
+ def filter_greys
122
+ @possible_words.select! do |word|
123
+ !@greys.any? { |letter| word.include?(letter) }
124
+ end
125
+ end
126
+
110
127
  def check_word_correct(letters)
111
128
  letters.length != 2 || !%w[s y g].include?(letters[0])
112
129
  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.1 ruby lib
5
+ # stub: wordl-solver 0.2.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "wordl-solver".freeze
9
- s.version = "0.2.1"
9
+ s.version = "0.2.2"
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-05"
14
+ s.date = "2022-04-06"
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.1
4
+ version: 0.2.2
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-05 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda