Prev: Ruby Basic
Next: Ruby Basic
From: Lars Haugseth on 24 Jun 2010 20:05 Here's a quick solution visualized using Rubygame¹: http://www.pastie.org/1018079 I'm sorry about the lack of comments (the code should be mostly self-explanatory, if not just ask.) -- Lars Haugseth [1] http://rubygame.org/
From: Lars Haugseth on 24 Jun 2010 20:09 * Benoit Daloze <eregontp(a)gmail.com> wrote: > > I had an intuition doing some Math.sqrt about the distance, and it > revealed to be exact :) I bet you didn't do that right from the start, before seeing the first results? At least I didn't. :-) -- Lars Haugseth
From: Benoit Daloze on 25 Jun 2010 06:57 On 24 June 2010 21:24, Yaser Sulaiman <yaserbuntu(a)gmail.com> wrote: > [...] although I have to admit that > talking about generating random vectors sounds "cooler" :P Yes, and a Point + Point is not as meaningful > Because I'm not using Vectors anymore, Point + Point now performs > the equivalent 2D translation. Also, Point.distance_to now uses Math.hypot. Cool, but I believe your implementation of Point#+ is somehow bad, because it returns @y. So you probably want to return self if you accept the Point objects to be mutable, or create a new Point, which is a bit safer, but creates a new object (in both cases you could definitely get rid of this awful "return p" :) ) Also, @@origin should not be modified, and then should be a constant, and be #freeze if you want Point to be mutable. On 25 June 2010 03:05, Lars Haugseth <njus(a)larshaugseth.com> wrote: > * Benoit Daloze <eregontp(a)gmail.com> wrote: >> >> I had an intuition doing some Math.sqrt about the distance, and it >> revealed to be exact :) > > I bet you didn't do that right from the start, before seeing the > first results? At least I didn't. :-) > -- > Lars Haugseth I thought while writing it (without sqrt) that it was going wrong, and the next day I thought to sqrt. The night is a good adviser :-) B.D.
From: Yaser Sulaiman on 25 Jun 2010 09:30 [Note: parts of this message were removed to make it a legal post.] On Fri, Jun 25, 2010 at 1:57 PM, Benoit Daloze <eregontp(a)gmail.com> wrote: > Cool, but I believe your implementation of Point#+ is somehow bad, > because it returns @y. > So you probably want to return self if you accept the Point objects to > be mutable, > or create a new Point, which is a bit safer, but creates a new object > (in both cases you could definitely get rid of this awful "return p" :) ) > > The _awful_ "return p" is now gone ;) I want Point objects to be mutable, so Point#+ returns self after modifying the x and y coordinates. > Also, @@origin should not be modified, and then should be a constant, > and be #freeze if you want Point to be mutable. Good point. The origin is now a "frozen" class constant.
From: timr on 27 Jun 2010 01:22
A thorough derivation of the distribution frequency transformation for the case of a circle. Behold the power of math! http://excitemike.com/Random_Numbers_and_Probability_Density_Functions |