Advertisement
Guest User

Untitled

a guest
Oct 18th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.48 KB | None | 0 0
  1. words = File.readlines('words_alpha.txt').map do |word|                                                                                                                                      
  2.   word.strip.upcase                                                                                                                                                                          
  3. end.select do |word|                                                                                                                                                                          
  4.   word.size == 5                                                                                                                                                                              
  5. end                                                                                                                                                                                          
  6.                                                                                                                                                                                              
  7. neighbours = Hash.new { |h, k| h[k] = [] }                                                                                                                                                    
  8. words.each do |word|                                                                                                                                                                          
  9.   5.times do |i|                                                                                                                                                                              
  10.     neighbours[word[...i] + "-" + word[i++1..]] << word                                                                                                                                      
  11.   end                                                                                                                                                                                        
  12. end                                                                                                                                                                                          
  13.                                                                                                                                                                                              
  14. neighbours.values.select{|v| v.size > 1}  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement