Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. dicts = Dir['/usr/share/dict/*'].reject { |f| f =~ /finnish|catalan|german/ }
  2. words = Hash.new { |h,k| h[k] = [] }
  3.  
  4. $stdout.sync = true
  5.  
  6. dicts.each_with_index do |d, i|
  7. str = ("[#{File.basename(d)}]".ljust(20) + "#{i}/#{dicts.size}")
  8. print str
  9. File.new(d, 'r').each_line do |word|
  10. word.strip!
  11. words[word.size] << [word, word.split('').sort]
  12. end
  13. print "\b" * (str.size + 1)
  14. end
  15.  
  16. loop do
  17. print "search: "
  18. searched = gets.strip
  19. size = searched.size
  20. splat = searched.split('')
  21.  
  22. results = []
  23. words[size].each do |word, splot|
  24. if splat.sort == splot
  25. results << word
  26. end
  27. end
  28. puts results.uniq.join(', ')
  29. end
Add Comment
Please, Sign In to add comment