in reply to search multiple lists

Smells like homework.

require 'pp' class Array def shuffle!( ) each_index {|i| j = rand(i+1); self[i], self[j] = self[j], self[i] +} end def shuffle( ) self.dup.shuffle! end end lists = (1..6).inject( [] ) { |m,o| m << [] } ( 1..50 ).to_a.shuffle.each { |x| lists[ rand(6) ] << x } target = Integer( rand( 50 ) + 1 ) pp lists list_no = nil lists.each_index { |i| list_no = i if lists[i].any? { |x| x == target +} } puts "#{target} is in list #{list_no}"

Replies are listed 'Best First'.
Re^2: search multiple lists
by Annemarie (Acolyte) on Mar 04, 2005 at 08:18 UTC
    Sorry, I am more of a 'baby perl' person. Your code looks a little like Egyptian hierroglyphs to me. Maybe one day I will be able to decipher. Thanks for your response. It's good to know that there is still heaps to learn! 8-)
      A book about Ruby may help you decipher... :-)