[Edu-sig] Brute force solutions

2005-09-20 Thread Kirby Urner
Per my 'Pentagon math' thread, I think the golden ratio (phi) is an important one to explore in K-12.[1] It's one of those key nodes in our curriculum network. Given a regular pentagon, the ratio of a diagonal to an edge is phi. In other words, that famous pentacle pattern is phi-edged, vis-à-v

Re: [Edu-sig] Brute force solutions

2005-09-21 Thread David Handy
I'm sorry, but I couldn't help taking Kirby's findphi() function as a personal challenge. At the cost of roughly doubling the complexity of the code (19 lines instead of ten lines in the function body), I was able to improve the performance by a factor of more than 6500, while basically still usin

Re: [Edu-sig] Brute force solutions

2005-09-21 Thread Kirby Urner
> (Yes, I know the original version wasn't claimed to be optimized, but it > was crying to be optimized...) > Yes. This is a valuable addition to the thread. Thanks for taking the time. Reminds me of when Tim Peters used to swing by in the early days of edu-sig and optimize the hell out of my

Re: [Edu-sig] Brute force solutions

2005-09-21 Thread Peter Bowyer
At 14:33 21/09/2005, you wrote: >At the cost of roughly doubling the complexity of the code (19 lines instead >of ten lines in the function body), I was able to improve the performance by >a factor of more than 6500, while basically still using the same >"brute-force" approach of guessing a number,

Re: [Edu-sig] Brute force solutions

2005-09-21 Thread David Handy
On Wed, Sep 21, 2005 at 06:44:01PM +0100, Peter Bowyer wrote: > At 14:33 21/09/2005, you wrote: > >At the cost of roughly doubling the complexity of the code (19 lines instead > >of ten lines in the function body), I was able to improve the performance by > >a factor of more than 6500, while basica

Re: [Edu-sig] Brute force solutions

2005-09-21 Thread David Handy
On Wed, Sep 21, 2005 at 09:31:41AM -0700, Kirby Urner wrote: > Mine original draft makes sense to set the stage, cuz the reasoning is so > dang primitive. Yours adds a layer of sophistication more reflective of how > real world programmers learn to squeeze the most out of their cycles. Your origi

Re: [Edu-sig] Brute force solutions

2005-09-21 Thread John Zelle
David Handy wrote: > On Wed, Sep 21, 2005 at 09:31:41AM -0700, Kirby Urner wrote: > >>Mine original draft makes sense to set the stage, cuz the reasoning is so >>dang primitive. Yours adds a layer of sophistication more reflective of how >>real world programmers learn to squeeze the most out of

Re: [Edu-sig] Brute force solutions

2005-09-22 Thread John Zelle
> On Wed, Sep 21, 2005 at 09:31:41AM -0700, Kirby Urner wrote: > >Of course all of this requires temporarily ignoring the fact that algebraic >methods give us a way to compute phi as simply (1 + math.sqrt(5))/2.0. I've been considering this a bit. The closed form here begs the question, what i

Re: [Edu-sig] Brute force solutions

2005-09-22 Thread Daniel Ajoy
On 22 Sep 2005 at 12:00, (Kirby Urner) wrote: > > Some lessons that might be learned from this approach: > > > > (1) when working with floats, you want to compare differences, not check for > > equalities, e.g. looking for when b/a == 1/b would be a bad idea. > > > > (2) you get greater accuracy

Re: [Edu-sig] Brute force solutions

2005-09-22 Thread Arthur
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Daniel Ajoy > Sent: Thursday, September 22, 2005 10:07 AM > To: edu-sig@python.org > Subject: Re: [Edu-sig] Brute force solutions > > My approach to teaching about phi i

Re: [Edu-sig] Brute force solutions

2005-09-22 Thread Kirby Urner
> I've been considering this a bit. The closed form here begs the > question, what is math.sqrt(5)? Sure, we have a built-in function that > computes this, but someone had to write the algorithm that computes > sqrt. That calculation makes use of numerical techniques similar to what > we are discus

Re: [Edu-sig] Brute force solutions

2005-09-24 Thread Kirby Urner
> I've a couple times implemented the old manual algorithm for finding > square roots. I might be able to dig those up for discussion. The longer > it runs, the more digits you get. > > Kirby But instead, this steaming unoptimized octopus of a code specimen spits back the repeating digits for a

Re: [Edu-sig] Brute force solutions

2005-09-24 Thread [EMAIL PROTECTED]
>The fun part here is we can use numerator/denominator syntax with open-ended >precision integers, to like express sqrt of 19 as some humongous fraction >(as many digits as memory will allow). This lets us far surpass the >floating point barrier. For example, the sqrt of 19 is rougly: 7459690842

Re: [Edu-sig] Brute force solutions

2005-09-24 Thread [EMAIL PROTECTED]
>n = ((pow(orig,0.5) + addterm)/denom)**2 H, this may be the Achilles heal of my project, to not use any sqrt finder in the process of finding a sqrt using continued fractions. Back to the drawing board? Kirby mai

Re: [Edu-sig] Brute force solutions

2005-09-24 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: >>The fun part here is we can use numerator/denominator syntax with > > open-ended > >>precision integers, to like express sqrt of 19 as some humongous fraction >>(as many digits as memory will allow). This lets us far surpass the >>floating point barrier. OK, here we g