Created
February 6, 2017 20:06
-
-
Save PamBWillenz/7ed8305f079549d9896fbfecd2a12fe5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#module AnagramPuzzle | |
class Anagram | |
def initialize | |
@word_list = word_list | |
end | |
def word_list | |
# empty array | |
wl = [] | |
dictionary = File.open("/usr/share/dict/words") | |
dictionary.each do |line| | |
wl.push(line) | |
# puts line | |
end | |
return wl | |
end | |
def anagram_string(w) | |
valid_string = [] | |
word = w.split("").shuffle.join # rearranging the words | |
valid_string << word | |
puts valid_string.sample | |
# tell customer how to use this to make an anagram | |
end | |
def solve_anagram | |
# num_letters = word.length | |
# letters.include? in anagram word # use all the letters given | |
valid_anagrams = [] | |
words = anagram_string("w") | |
num_letters = words.length | |
@word_list.each do |word| | |
next unless word.length == num_letters | |
word_copy = word | |
word = word.split(//) | |
letters.each do |letter| | |
if word.include? letter | |
word.delete_at word.index(letter) | |
end | |
end | |
if word.length == 0 | |
valid_anagrams.push(word_copy) | |
end | |
end | |
valid_anagrams | |
end | |
end | |
anagram = Anagram.new() | |
# puts anagram.word_list.sample | |
# a = anagram.word_list.sample | |
# puts anagram.anagram_string(a) | |
puts anagram.solve_anagram | |
# DICTIONARY | |
# /usr/share/dict/words as the set of English words. | |
# num_letters = word.length | |
# go thru word list to provide anagram string to create puzzle | |
# @word_list.each do |word| | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment