From: Ryan Victory Date: 2013-01-30T05:52:52+09:00 Subject: Re: newbie question.. For the same reason, I won't give you any answers, but your problem could probably be solved using about two lines with the Array.inject method and a Hash...think about it and ask questions. We are all here to help, but we wouldn't want it to be too easy for you :-) -Ryan Victory On 1/29/13 2:50 PM, Wayne Brisette wrote: > Since this is classwork, I won't give you the answer, but. Here's some things I > would do (and trust me there are *much* smarter people on this list), but I > would do probably use the case statement here. Seems to be a logical holding > point for things. > > def sort_numbers(argv_input) > case = argv_input > when "1" one =+1 > etc... > > end > > numbers = ARGV.split(" ") > > numbers.each do |num| > > sort_numbers(num) > > ### put your print routine here ### > > end > Anyhow, that's how I would tackle it. But I'm sure there are better ways to code > this type of thing up. > > Wayne > > > ----- Original Message ---- > From: Zebulon Bowles > To: ruby-talk ML > Sent: Tue, January 29, 2013 2:41:28 PM > Subject: newbie question.. > > So I'm taking a class on Ruby and it seems as though the teacher has > thrown something over my head. > > > List how many times each number from 0 to 9 was mentioned. > Example input: > > ruby most-common.rb 4 2 1 1 1 2 > Example output: > 1 was mentioned 3 time(s). > 2 was mentioned 2 time(s). > 4 was mentioned 1 time(s). > The numbers in the command-line arguments must always be between 0 and > 9, inclusive. > > Do I loop over each element of an array of ARGV's and test to see if > each new element of the array is equal to any of the others. And if so, > do I set up a count? > > numbers = ARGV > > for number in numbers > if number > 0 && < 9 > ??????????????????? > > end > > puts "#{number} was mentioned #{count} times? > > AHHHGH!!!! >