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