Skip to content

{ Category Archives } project euler

Project Euler, Problem 10, In Erlang – Sieveless Edition

Problem 10, more primes. Sum the all primes under 2,000,000.
Probably meant to force you out of brute force trial division.
Probably want you to use the Sieve Of Eratosthenes.
And I thought about it.
Then tried trial division for fun.
Exactly 1 minute run time.
Done!
Heh.
Looking at future [...]

Project Euler, Problem 9, in Erlang

Problem 9, and more brute-forcey goodness for the solution.
“A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^(2) + b^(2) = c^(2)
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.”
I’m not totally happy with this one. I’m positive [...]

Project Euler, Problem 8, in Erlang

Problem 8 is another one of those problems that’s pretty simple to approach. The only even minor twist is that it’s probably best to use a string in this one. But easily enough done.
Some on the P.E. discussion boards even did this one with no programming, just a visual scan of the number.
“Find [...]

Project Euler, Problem 7, in Erlang

Ah, Problem 7, the one we knew was coming.
“What is the 10001st prime number?”
The basics are simple enough. Brute force a primality test via trial division and use the test to find 10001 prime number. So I did that, got the answer.
But it took 2:24 on my netbook, and [...]

Project Euler, Problem 6, in Erlang

Problem 6 was surprisingly straight-forward.
“Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.”
Really, just a straight-forward calculation, easily implemented in Erlang recursive-speak. No real comments on this one.

-module(euler6).
-export([difference/1]).

difference(N) ->
SumSquare = sumofsquares(0,N),
[...]

Project Euler, Problem 4, in Erlang

Problem 4 is an interesting one. “A palindromic number reads the same both ways. Find the largest palindrome made from the product of two 3-digit numbers.”
I thought about this for a few minutes and decided the best way to approach it would be to build candidate palindromic numbers and and then test them to [...]

Project Euler, Problem 5, in dirty dirty Erlang

I did complete Problem 4 already, but the write up will take a bit of time. So I went ahead and did Problem 5, in a very quick and dirty way.
Problem 5 – “What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?”
The total [...]

Project Euler, Problem 3, in Erlang

When I first read Problem 3 I thought it was going to be more involved than it turned out to be.
“What is the largest prime factor of the number 600851475143 ?”
And I started thinking I’ll need to list the factors and test them for primality, or find primes first and test only [...]

Project Euler in Erlang, Problem 2

Problem 2 is again stated simply- “Find the sum of all the even-valued terms in the (Fibonacci) sequence which do not exceed four million.”
The Fibonacci Sequence is the sequence which runs 1, 2, 3, 5, 8, 13, 21 etc. in which each term is the sum of the previous two terms.
Again, conceptually easy. [...]

Project Euler, Problem 1

Getting started with my quest via my first attempt at a solution in Erlang to Project Euler’s problem number 1.
The problem itself is simply stated : “Find the sum of all the multiples of 3 or 5 below 1000.”
A naive algorithm is immediately apparent- cycle through each number between below 1000 and sum those that [...]