Daniel Finnie
1/10/2007 8:19:00 PM
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
>