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


Groups > comp.lang.forth > #44091

Scrabble problem

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Scrabble problem
Date 2015-12-05 17:55 +0000
Organization A noiseless patient Spider
Message-ID <n3v8fa$otf$1@dont-email.me> (permalink)

Show all headers | View raw


Given a rack of letters, find all of the words in
a file containing one word per line that can be
formed from that rack.


Ruby:

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"]

This was easy in Ruby, but I feel sorry for anyone who has to solve
this in the Toy Language (ANS Forth).

Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Scrabble problem "WJ" <w_a_x_man@yahoo.com> - 2015-12-05 17:55 +0000
  Re: Scrabble problem Julian Fondren <julian.fondren@gmail.com> - 2015-12-05 11:41 -0800
    Re: Scrabble problem Julian Fondren <julian.fondren@gmail.com> - 2015-12-05 11:51 -0800
  Re: Scrabble problem "WJ" <w_a_x_man@yahoo.com> - 2015-12-06 02:00 +0000

csiph-web