From: Daniel Finnie Date: 2007-01-11T05:18:59+09:00 Subject: Re: [QUIZ][SOLUTION] Word Blender (#108) That makes sense :). On a side note, I did make some methods for getting a rand value from any enumerable (they can be integrated as instance methods): def rand_value_each(enum) index = rand(enum.size) curr = 0 enum.each {|x| return [x].flatten.last if curr == index; curr += 1 } end def rand_value_to_a(enum) [rand_value_ary(enum.to_a)].flatten.last end def rand_value_ary(ary) ary[rand(ary.size)] end Dan Ken Bloom wrote: > On Wed, 10 Jan 2007 11:17:24 +0900, Daniel Finnie wrote: > >> Hi Ken, >> >> Ken Bloom wrote: >>> #load dictionary >>> matcher=Set.new >>> allwords=Array.new >>> thiswordmatcher=Set.new >> I'm interested in why you used a set for matcher and an array for >> allwords. Was this a kindof random decision (many of mine are!) or is >> there something that allwords needed to be able to do and so is an array >> or vice versa? > > allwords needs array indexing to pick a random word from the array. > The sets, however, need duplicate removal and/or need include? to operate > in O(1). > > --Ken >