Re: Getting the smallest Items of an Array

2012-11-29 Thread Robert Klemme
On Thu, Nov 29, 2012 at 4:42 PM, Regis d'Aubarede wrote: >> def n_min(l,n) (1..n).map {a=l.min ; l=l-[a]; a } end >> >> array.sort[0, n] >> n_min array, n > > > You compar ruby implementation for n_min() with c implementation for > sort... Is that forbidden? You are making us

Re: Getting the smallest Items of an Array

2012-11-29 Thread Robert Klemme
On Thu, Nov 29, 2012 at 12:02 PM, Regis d'Aubarede wrote: >>> def n_min(l,n) (1..n).map {a=l.min ; l=l-[a]; a } end > => nil >>> n_min([1,2,-1,3,4],2) > => [-1, 1] Without having measured it that's quite an inefficient way to do it IMHO: - you are creating a lot temporary arrays (two for each ste

Re: Getting the smallest Items of an Array

2012-11-29 Thread Иван Бишевац
Try this: n = [4, 6, 7, 2, 15] def min(n) minimum = n[0] n.each do |element| if element < minimum minimum = element end end return minimum end puts min(n) -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to

Re: Simple script not working

2012-11-29 Thread Robert Klemme
On Thu, Nov 29, 2012 at 10:32 AM, Prog Rammer wrote: > Joel Pearson wrote in post #1087040: >> It looks like your browser can't establish a connection. Firewall? > > I can see that it opens few ie window and then throws the error. Even on > irb i can atart a browser and go to url etc.. You may al

Re: sorting data from a file

2012-11-29 Thread Иван Бишевац
If you want to go through all rows then you type: @csv.each do |row| # do something with row end -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this

Re: sorting data from a file

2012-11-29 Thread Иван Бишевац
It's beginner question. My advice is that you go through some beginners tutorial about Ruby. After that you will know to implement it. Here is your starting code: require 'csv' class ParseCSV def initialize @csv = CSV.read "data.csv" end def test @csv[0] # it's first row end end pc = ParseCSV

Re: Newbie question: (free) on-line courses?

2012-11-29 Thread Иван Бишевац
https://www.edx.org/courses/BerkeleyX/CS169.1x/2012_Fall/about is great online course for Software as a Service with Ruby in mind. There is 2nd part of it on edx.org site, but it's advanced. You will learn Ruby by example, and best practices. 2nd part course: https://www.edx.org/courses/BerkeleyX/C