Project Euler
Mick Collins
mickclns at mac.com
Fri Feb 26 19:02:57 EST 2010
Mike, 'scool, thanks.
Brian, I agree, great project for math and coding. Sometimes it's an enlightening exercise to take an existing capability and code it oneself or to extend it. For instance, I have written routines to do "infinite" precision integer arithmetic (working on an "infinite" precision calculator), to do a sortof baseConvert, but which will accept decimals or fractions and bases larger than 36, intermediately large (10^12+) prime factorization and at one time in I wrote some routines to mimic trig functions. As far as sqrt, back in the old days when I was in high school, we learned to extract those by hand ... you, too?
>From: Michael Kann <mikekann at yahoo.com>
>Subject: Re: Project Euler
>To: How to use Revolution <use-revolution at lists.runrev.com>
>Message-ID: <327364.51145.qm at web56701.mail.re3.yahoo.com>
>Content-Type: text/plain; charset=iso-8859-1
>
>Mick,
>
>You beat me to it on the Fibonacci series. I also thought about using the golden ratio. Using a few other relationships allows one to compose a rather compact script.
>
>1. the F numbers are always odd odd even, odd odd even
>is
>--- before four million
>
>2. F1 + F2 + F3 . . . Fn = F(n+2)- 1
>
>--- this allows you to do the summation at the end
>--- If you know Fn then you just go up a couple more
>--- numbers to get the sum of the first n numbers
>
>3. If you stop the summation at F(even) then the sum of
> the even numbers will be 1/2 of the total sum
>
>-- 1,1,TWO,3,5,EIGHT,13,21,THIRTY-FOUR
>-- The two numbers sum to the EVENS (by definition)
>
>----Here's the script -- 555 is just any large number
>
>on mouseUp
>put (1+ sqrt(5))/2 into g
>repeat with n = 0 to 555 step 3
> if (g^n)/sqrt(5) > 4E6 then exit repeat
>end repeat
>put (round((g^(n-1))/sqrt(5)) - 1) / 2
>end mouseUp
>-------------------------------------
>The golden ratio technique is most valuable if you want to hit a very large F number. You don't have to count up to it. It is like random access memory.
>
>
>
>Here's another interesting property of a F series:
>
>1 1 2 3 5 8 13 21
>
>Take the square of 8 -- 64. It is off by one from the product 5*13. That holds for any 3 numbers in a row. Sometimes the square is one more than the products of its neighbors, sometimes one less: but always one off.
>
>
**********************************************
>Date: Thu, 25 Feb 2010 16:27:38 -0500
>From: Brian Yennie <briany at qldlearning.com>
>Subject: Re: Project Euler
>To: How to use Revolution <use-revolution at lists.runrev.com>
>Message-ID: <A4DB603E-27D8-4404-B01D-8D24B9B9737B at qldlearning.com>
>Content-Type: text/plain; charset=us-ascii
>
>Good stuff! I particularly like this project, because it allows for a combination of clever coding AND pure math. The best problems surely require both. It also depends what "level" of computation you force yourself to contain in you code. For example, Rev has a sqrt() function, but what if you had to write this code without that function built in? Would that lead to a whole different approach? Is it ok to use known formulas, or does your code have to derive them itself? Etc.
>
>With that said, it would be pretty darn cool if we got a near-complete set of solutions all written in Rev... what a nice reference for tight mathematical coding.
More information about the Use-livecode
mailing list