Erlang & Project Euler

Just a quick and fairly simple post. I've been reading Programming Erlang over the last few days and decided tonight to have a quick play with the Project Euler problems (having never done them before). Here ~10 minutes work :)

%% Erlang Solution to Project Euler Problem #2 %% "Sum of all even primes under one million" %% Written by Darcy Laycock %% http://blog.ninjahideout.com/ -module(pe). -compile(export_all). start() -> process(1000000). process(Max) -> io:format("Calculating All Even Fib. Under ~p~n", [Max]), evenFactorialsUnder(1, 1, Max, 0). printResults(0) -> io:format("No Known Results.~n"); printResults(Results) -> io:format("Found Result:~n~p~n", [Results]). evenFactorialsUnder(A, B, Max, Acc) when A+B > Max -> printResults(Acc); evenFactorialsUnder(A, B, Max, Acc) -> NewNum = A + B, case NewNum rem 2 of 0 -> %% even evenFactorialsUnder(NewNum, A, Max, Acc + NewNum); 1 -> %% odd evenFactorialsUnder(NewNum, A, Max, Acc) end.

Edit: More of these coming tonight :) Simple but fun!

Posted by in Programming and it's been tagged as erlang, programming, problem & maths. There are currently zero comments.


Learning Languages

As a programmer, one of the things I enjoy the most is the structure of languages - how inherently different styling can mould the experience I have when learning it. As an offshoot of this, I've slowly become interested in different programming languages and how they can be used in everyday life.

(Please view full post for more.)

Posted by in Programming and it's been tagged as programming, languages, erlang & haskell. There are currently zero comments.