Skip to content

Instantly share code, notes, and snippets.

@agoodman
Created May 24, 2012 22:42
Show Gist options
  • Save agoodman/2784660 to your computer and use it in GitHub Desktop.
Save agoodman/2784660 to your computer and use it in GitHub Desktop.
Word Pruning by Letter Subtraction
possible_words = ["seek", "find", "ignore", "pursue", "covet"]
available_letters = ["a", "c", "e", "f", "g", "i", "n", "o", "p", "r", "t", "u", "v"]
words = Array[possible_words].flatten
available_letters.each {|e| words = words.map {|w| w.sub(e, '')}}
viable_words = words.each_with_index.collect {|w,k| possible_words[k] if w==""}.compact
@jeffreybaird
Copy link

Okay so I think the next move is to create an array of hashes of the letters and their values that matches each word and then we can use that later in the board.

@jeffreybaird
Copy link

word_as_hash = Array.new
viable_words.each do |word|
i = 0
x = word.size
while x > i
word_as_hash << word[i].to_sym
i += 1
end
end

okay so that successfully changes each character to a hash but doesn't keep the words as separate arrays. Ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment