Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-25 Thread Aviad Reich
thanks! On 25 February 2010 15:28, fra wrote: > Hi, > > I have a small improvement. > The function / called with only argument returns the inverse, so you > can define g-mean and h-mean more shortly: > > (defn g-mean [coll] > (expt (reduce * coll) (/ (count coll > > (defn h-mean [coll] ;;

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-25 Thread fra
Hi, I have a small improvement. The function / called with only argument returns the inverse, so you can define g-mean and h-mean more shortly: (defn g-mean [coll] (expt (reduce * coll) (/ (count coll (defn h-mean [coll] ;; Michael Kohl's function (/ (count coll) (reduce + (map / coll)))

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-25 Thread Aviad Reich
here is the final version of the implementation. http://gist.github.com/313558 again, any thought would be great. Aviad. On 22 February 2010 22:11, Aviad Reich wrote: > I don't mean to signal the end of this thread, but I just wanted to thank > you all for you replies. > I will update the draf

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-22 Thread Aviad Reich
I don't mean to signal the end of this thread, but I just wanted to thank you all for you replies. I will update the draft (and add Colin and Mikel's infinite seq code as well) possible in a day or two (no at home till then), and post the new code before posting to Rosetta. Cheers, Aviad On 22 F

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-22 Thread Michael Kohl
On Mon, Feb 22, 2010 at 11:43 AM, Johnny Kwan wrote: > Whichever is faster depends on the size of the argument list I see, thanks for clarifying. I'd then change my version to this since I still like map with an anonymous function more than the for-comprehension in this case. defn h-mean [coll]

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-22 Thread Meikel Brandmeyer
Hi, On Feb 22, 11:43 am, Johnny Kwan wrote: > (time (reduce + (range 1 1000))) ; 4.5 secs on my Macbook Air > (time (apply + (range 1 1000))) ; OutOfMemory error Ah. It holds unto the head. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-22 Thread Johnny Kwan
Hi, On Feb 22, 2010, at 1:43 AM, Meikel Brandmeyer wrote: > Hi, > > On Feb 22, 12:18 am, Johnny Kwan wrote: >> I'm really new to Clojure, but I'm under the impression that reduce would >> be better than apply, since I assume that apply would reify the entire >> sequence at once, whereas reduce

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread Meikel Brandmeyer
Hi, On Feb 22, 2:30 am, trptcolin wrote: > I do have a feeling I'm missing something really obvious that would > make my example simpler, so if anybody has any tips I'd be much > obliged! Using OP's code: (let [numbers (take 1000 (fibs))] (println (a-mean numbers) ">=" (g-mean numbers) ">="

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread Meikel Brandmeyer
Hi, On Feb 22, 12:18 am, Johnny Kwan wrote: > I'm really new to Clojure, but I'm under the impression that reduce would > be better than apply, since I assume that apply would reify the entire > sequence at once, whereas reduce would consume the sequence one by one. > Could someone more familiar

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread trptcolin
Aviad, Nice job! One nitpick is that won't work for infinite sequences, since reduce isn't lazy. If you wanted your definitions to work for arbitrary indexes of infinite sequences (like the Fibonacci numbers), you could provide sequences providing successive results for the input sequences. I d

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread Michael Kohl
On Mon, Feb 22, 2010 at 12:18 AM, Johnny Kwan wrote: > I'm really new to Clojure, but I'm under the impression that reduce would be > better than apply, since I assume that apply would reify the entire sequence > at once, whereas reduce would consume the sequence one by one. I was going by this

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread Johnny Kwan
I'm really new to Clojure, but I'm under the impression that reduce would be better than apply, since I assume that apply would reify the entire sequence at once, whereas reduce would consume the sequence one by one. Could someone more familiar with the implementation weigh in on this? On Feb

Re: Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread Michael Kohl
On Sun, Feb 21, 2010 at 9:41 PM, Aviad Reich wrote: > ANY comments will be great (including: this is all wrong - don't > post it). FWIW since I'm not exactly an expert on idiomatic Clojure either, I'd write h-mean like this: (defn h-mean [coll] (/ (count coll) (apply + (map #(/ 1 %) coll

Newbie suggestion for an implementation - rosettacode pythagorean means

2010-02-21 Thread Aviad Reich
Hi everyone, being a newb to clojure, my ability to contribute to is still limited. However, I thought I'll try starting with something simple. http://rosettacode.org/wiki/Averages/Pythagorean_means seems straightforward enough, but since it's a comparative site, and implementations should be as