Wednesday
May092012

Project Euler - Problem 5

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

This was a neat question could be brute forced easily but that would be very slow. There is a table method which exploits the properties of prime numbers to find least common multiple of a set of numbers. The exact method can be found on the least common multiple wikipedia page

Saturday
May052012

Project Euler - Problem 4

Find the largest palindrome made from the product of two 3-digit numbers.

A palindrome is a string which reads the same forwards and backwards for example 98789. The isPalinedrome(x) method checks if x is a palindrome by checking if x equals x in reverse. The n[::-1] call returns the reverse of n. The stride notation lets you filter in a interval of elements in a list. For example the call n[::2] for n = [1,2,3,4]   would return [2,4]. Then a nested for loop is used to find the biggest palindrome made of the product 3 digit integers.

Friday
May042012

RIP Adam 'MCA' Yauch of the Beastie Boys

Pretty bummed about lossing MCA today. Been a fan for as long as I can remember. There's pretty much always been a Beastie Boys album in my rotation from Hello Nasty to the Mix Up. Here's a homage to sabotage that me and some friends made while finishing up highschool.

Wednesday
May022012

Project Euler - Problem 3

What is the largest prime factor of the number 600851475143 ?

This problem is a little tricky the solution looks simple but there are a few key things that let it run quickly. First we take the square root of 600851475143 and start searching from that value to zero. We can look in this range because any factor greater than the square root would have a multiple below it and thus not be prime. The second thing to note is the if statement which checks if we have found a solution. We check if it is factor before checking if it is prime. This cuts down on the number of expensive prime checks because they are only done after confirming that a value is a factor of 600851475143. This is because the 'and' statement returns false after the first operand is checked and doesn't waste time computing the second one (the prime test)

Tuesday
May012012

Project Euler - Problem 2

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Problem 2 of project euler is another simple one. The next value in the fibonacci sequence is the sum of the previous 2 values. As we produce the next value in the fibonacci sequnece we sum up the even values.