Blog Archives

NumPy Project Euler Problem 1

This entry is part 1 of 9 in the series NumPy Project Euler

Project Euler is a website that lists a number of mathematical problems, which are perfect to be solved with NumPy. Let’s start the new year with Problem 1.
1. Call the arange function
Call the arange function in order to store all [...]

Share
Posted in programming | Tagged , | Leave a comment

NumPy Project Euler Problem 2

This entry is part 2 of 9 in the series NumPy Project Euler

Project Euler Problem 2 is definitely harder than Problem 1. This one requires reading the Fibonacci numbers Wikipedia article.
I read that the Project Euler problems are some sort of katas. Katas are what martial artist call exercises, preparing you for [...]

Share
Posted in programming | Tagged , | Leave a comment

NumPy Project Euler Problem 3

This entry is part 3 of 9 in the series NumPy Project Euler

Project Euler Problem 3 seems almost impossible to crack. However, using the right algorithm – Fermat’s factorization method and NumPy, it becomes very easy. The idea is to factor a number N into two numbers c and d.

[...]

Share
Posted in programming | Tagged , | Leave a comment

NumPy Project Euler Problem 4

This entry is part 4 of 9 in the series NumPy Project Euler

Project Euler Problem 4 is a bit silly. It’s about palindromic numbers. I could not find an appropriate algorithm, so I just tried something out. It seems to work OK.
1. Create a 3-digit numbers array
We will create an array to [...]

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 5

This entry is part 5 of 9 in the series NumPy Project Euler

Project Euler Problem 5is one of those problems that seem hard, but turn out to be trivial after you think about them. In this case it is very important to use the information given to you in the problem. This [...]

Share
Posted in programming | Tagged , , | Leave a comment

NumPy Project Euler Problem 6

This entry is part 6 of 9 in the series NumPy Project Euler

Project Euler Problem 6 is perfect to demonstrate the power of NumPy. No loops are required and only a few lines of code.
1. Create an array with the first 100 natural numbers
First we will create a NumPy array of the [...]

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 7

This entry is part 7 of 9 in the series NumPy Project Euler

Project Euler Problem 7 is about prime numbers. So I implemented a Sieve of Eratosthenes with NumPy. I am not following the algorithm to the letter, but I believe that the result is the same.
1. Create a list of consecutive [...]

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 8

This entry is part 8 of 9 in the series NumPy Project Euler

Project Euler Problem 8 requires a lot of string manipulation. Still we have some opportunities to practice our NumPy skills.
1. Calculate the product of the 5 element array
First we need to compute the product of an array with 5 elements. [...]

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 9

This entry is part 9 of 9 in the series NumPy Project Euler

var dzone_url = “http://ivanidris.net/wordpress/index.php/2012/02/27/numpy-project-euler-problem-9″;
var dzone_title = “NumPy Project Euler Problem 9″;

Project Euler Problem 9 is a tough one. After reading the Pythagorean Triple Wikipedia page, I implemented a NumPy solution with Euclid’s Formula.

1. Create m and n arrays
The Euclid’s Formula [...]

Share
Posted in programming | Tagged , , , | Leave a comment