Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7158

Scrabble problem

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.ruby
Subject Scrabble problem
Date 2015-12-06 16:06 +0000
Organization A noiseless patient Spider
Message-ID <n41mde$tui$1@dont-email.me> (permalink)

Show all headers | View raw


def good_word? word, sorted_rack
  word.split("").group_by{|x| x}.map{|k,v| v.join}.
  all?{|s| sorted_rack.index s}
end

def find_in_file filename, rack
  sorted_rack = rack.split("").sort.join
  IO.readlines(filename).map(&:strip).
  select{|word| good_word? word, sorted_rack}
end


find_in_file "words", "qwerty"
    ==>["e", "er", "et", "q", "r", "re", "rye", "t", "te", "ter", "tr", "trey",
"try", "tw", "tyr", "tyre", "we", "wet", "wry", "y", "ye", "yet", "yew"]

Back to comp.lang.ruby | Previous | Next | Find similar


Thread

Scrabble problem "WJ" <w_a_x_man@yahoo.com> - 2015-12-06 16:06 +0000

csiph-web