Project Euler
|
|
Alex
|
Sat Nov 29 2008, 04:18AM
|
|
|
Geometrically Frustrated
Registered Member #6
Joined: Thu Feb 02 2006, 04:18AM
Location: Bowdoin, Maine
Posts: 373
|
I've recently been doing problems on Project Euler. It's a neat site. There's a large list of problems, and the challenge is to come up with algorithms to solve them. Once you have an answer, you can test it. It's a bit of a competition, but for the most part it's just fun to test your skills. I started out with C, but I thought it would be neat to learn how to write algorithms in forth, so I've gone back and started over.
Anyone else want to give it a whack? Post your solutions if you think you've done something particularly clever.
I'll start out with my solution to Problem 2:
: fibonacci ( -- ) ( prints the sum of all even valued terms in the fibonacci sequence below 4000000 )
0 1 2
begin
dup 2 mod 0<> if
else
rot swap dup rot + -rot
then
dup rot +
dup 4000000 >
until
drop drop . ;
|
Back to top
|
|
Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob
|
|
Powered by e107 Forum System
|