wordl-solver 0.1.2 → 0.2.0

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: 7ecf240e631447599031404b10f864303511856e3c2d49f2bd9d20297e109a50
4
- data.tar.gz: 4be0ee26f1e2592aab9f0081c44d29790cb71348f9c9fd891535caaedd2bb5c1
3
+ metadata.gz: 1a115c6fe97a7be5c20fa342648e72f14bbe8e578dd3d7204a8846cf95cb31b1
4
+ data.tar.gz: 7ab4807987425e3cd4f177ddf4d895c242fc01f02c49d722677d41630812775b
5
5
  SHA512:
6
- metadata.gz: 5d4ee82f1b62e52d686337f108a98052ef843accdba05489156421894ed19b4537ae046c2b4a16ad97a932bbde9fbfde8d100ba29180c2ffc42df680708d1cd1
7
- data.tar.gz: c28f7ae9d5eb2db447c4fc7bcc3504e59660f2073e1c951e51b7a831211a09ce5f2a3096f05676dcbd488ff08d02e46fd6c8ada0253b87b4ed0c9b3dacb05ebb
6
+ metadata.gz: 2fb544f435ccc785b7e20e11795ac193c31f3eeaf2d336cc37411a4fd1636ea493c88b48ccc3543ada47930bd02392b0abf9c8d3233529398df17375d9772a0f
7
+ data.tar.gz: 1ba1caae3f9b0816187e5aa9262c7f4e30699bebcdc8ebcfec543fd90ee069bd4c14425fbf2a8447092c2bb669dafa2be559ae4a77040a1b3c7a382656d90089
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Juwelier::Tasks.new do |gem|
20
20
  gem.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."
21
21
  gem.email = "gkosmo1@hotmail.com"
22
22
  gem.authors = ["george kosmopoulos"]
23
- gem.files.include "lib/**/*"
23
+ gem.files.include "lib/*"
24
24
  # dependencies defined in Gemfile
25
25
  gem.executables = ['wordl-solver']
26
26
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/lib/wordl-solver.rb CHANGED
@@ -1,66 +1,98 @@
1
1
  require "csv"
2
2
  require "fileutils"
3
3
 
4
- FILE_PATH = "5_words.csv"
4
+ FILE_PATH = File.join( File.dirname(__FILE__), '5_words.csv')
5
+
5
6
  LETTER_WORDS = []
6
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)
7
- INITIAL_POSITIONED_LETTER_MESSAGE = "enter in order the letters for which you know the position \n if you don't know the position press enter"
8
- INITIAL_EXISTING_LETTER_MESSAGE = "enter all the letters you know exist in the word but for which you don't know the position"
9
- INITIAL_NOT_EXISTING_MESSAGE = "enter all the letters you know DO NOT exist in the word"
10
- POSITIONED_LETTER_MESSAGE = "enter all the letters in their position \n if you don't know the position press enter"
11
- EXISTING_LETTER_MESSAGE = "add the letters you know exist in the word but for which you don't know the position"
12
- NOT_EXISTING_MESSAGE = "enter all the letters you know DO NOT exist in the word"
13
8
 
14
9
  CSV.foreach(FILE_PATH) do |row|
15
10
  LETTER_WORDS << row[0]
16
11
  end
12
+
17
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
18
32
 
19
33
  def self.run
20
34
  WordlSolver.new.run
21
35
  end
22
36
 
23
37
  def run
24
- existing_letters, not_existing_letters, posish = initial_run
25
- iterating_run(existing_letters, not_existing_letters, posish)
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
26
45
  end
27
46
 
28
- private
47
+ private
29
48
 
30
- def ask_and_list_words(positioned_letter_message, existing_letter_message, not_existing_message, existing_letters, not_existing_letters, posish)
31
- puts positioned_letter_message
32
-
33
- posish.each do |position, value|
34
- if value.nil? || value == ""
35
- puts "for position #{position + 1} enter a letter"
36
- posish[position] = gets.chomp
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
37
68
  else
38
- puts "for position #{position + 1} you've found: #{value}"
69
+ puts "for position #{t + 1} this #{@greens[t]}"
39
70
  end
40
71
  end
41
- puts existing_letters
42
- puts existing_letter_message
43
- exist = existing_letters | gets.chomp.split('')
44
- puts not_existing_message
45
- puts not_existing_letters
46
- not_exist = not_existing_letters | gets.chomp.split('')
72
+ return [@greens, @yellows, @greys]
73
+ end
74
+
75
+ def find_possible_words
47
76
  possible_words = []
48
77
  LETTER_WORDS.each do |word|
49
78
  put_in = true
50
- posish.each do |key, value|
51
- next if value == ""
79
+ @greens.each do |key, value|
80
+ next if value == nil
52
81
  put_in = false unless word[key] == value
53
82
  end
54
83
  possible_words << word if put_in
55
84
  end
56
- possible_words = possible_words.select do |word|
57
- exist.all? { |letter| word.include?(letter) }
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
58
91
  end
59
-
60
92
  possible_words = possible_words.select do |word|
61
- !not_exist.any? { |letter| word.include?(letter) }
93
+ !@greys.any? { |letter| word.include?(letter) }
62
94
  end
63
- "here are the existing words"
95
+ puts "here are the existing words"
64
96
  hash_word_frequency = Hash.new()
65
97
  possible_words.each do |word|
66
98
  count = 0
@@ -71,41 +103,11 @@ class WordlSolver
71
103
  end
72
104
  hash_word_frequency = hash_word_frequency.sort_by { |k, v| v }
73
105
  hash_word_frequency.first(30).each do |word, count|
74
- puts "#{word} : #{count}"
106
+ p "#{word} : #{count}"
75
107
  end
76
- return [exist, not_exist, posish]
77
- end
78
-
79
- def initial_run
80
- existing_letters = []
81
- not_existing_letters = []
82
- posish = {
83
- 0 => nil,
84
- 1 => nil,
85
- 2 => nil,
86
- 3 => nil,
87
- 4 => nil,
88
- }
89
- history = ask_and_list_words(INITIAL_POSITIONED_LETTER_MESSAGE, INITIAL_EXISTING_LETTER_MESSAGE, INITIAL_NOT_EXISTING_MESSAGE, existing_letters, not_existing_letters, posish)
90
- puts "have you found it ? (y/n)"
91
- answer = gets.chomp
92
- existing_letters = history[0]
93
- not_existing_letters = history[1]
94
- puts "existing letters"
95
- puts existing_letters.join(" - ")
96
- puts "not existing letters"
97
- puts not_existing_letters.join(" - ")
98
- return [existing_letters, not_existing_letters, posish]
99
108
  end
100
109
 
101
-
102
- def iterating_run(existing_letters, not_existing_letters, posish)
103
- answer = nil
104
- until answer == 'y'
105
- existing_letters, not_existing_letters, posish = ask_and_list_words(POSITIONED_LETTER_MESSAGE, EXISTING_LETTER_MESSAGE, NOT_EXISTING_MESSAGE, existing_letters, not_existing_letters, posish)
106
- puts "have you found it ? (y/n)"
107
- answer = gets.chomp
108
- end
109
- puts 'you found it!'
110
+ def check_word_correct(letters)
111
+ letters.length != 2 || !%w[s y g].include?(letters[0])
110
112
  end
111
113
  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.1.2 ruby lib
5
+ # stub: wordl-solver 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "wordl-solver".freeze
9
- s.version = "0.1.2"
9
+ s.version = "0.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-03-24"
14
+ s.date = "2022-04-05"
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.1.2
4
+ version: 0.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-03-24 00:00:00.000000000 Z
11
+ date: 2022-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda