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}"
In reply to Re: search multiple lists
by Fletch
in thread search multiple lists
by Annemarie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |