Commit b43a33e

mo <mokha@cisco.com>
2017-05-19 02:59:57
change matching to check position of matches.
1 parent 106e1e7
Changed files (1)
spec/word_ladder_spec.rb
@@ -42,11 +42,13 @@ DOC
 
 describe "word_ladder" do
   def match?(word, other, length: word.chars.size)
-    (word.chars & other.chars).count == length - 1
+    #(word.chars & other.chars).count == length - 1
+    transposed = [word.chars, other.chars].transpose
+    matching = transposed.find_all { |(x, y)| x == y }.count
+    matching >= length - 1
   end
 
   def word_ladder(words, begin_word:, end_word:)
-    puts [begin_word, end_word, words].inspect
     return 0 if words.empty?
     return 0 if begin_word == end_word