Project Euler

Brian Yennie briany at qldlearning.com
Thu Feb 25 16:27:38 EST 2010


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.

> 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
> 
> --- this allows you to use "step 3" in the loop
> --- you will only check even numbers and stop at the last one
> --- 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.  




More information about the use-livecode mailing list