Euler: Problem 1

March 30, 2010

In a vain attempt to become productive and cultivate motivation and some kind of order into my otherwist Street Fighter 4 driven life I’m attempting to get all of the Project Euler puzzles done and to write a little bit about my solution and writing a better solution. In some, probably most, cases, I will also have to go through some theory of how I got to the solution.

The first puzzle has to do with finding the sum of a series of natural numbers. It’s very close to a question that I’ve added to our list of interview questions recently labelled FizzBuzz.

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

If you know how to program, or program on a regular basis the answer to this is quite straight forward and has the following steps.

  1. For each number, starting at 1 and ending with 100
  2. If the number divided by three has zero remainder output Fizz
    • If the number divided by five ALSO has a zero remainder output Buzz
  3. If the number divided by five has zero remainder output Buzz
  4. Otherwise, output the number

What we can do here, is replace the outputting of Fizz and Buzz with a summation of that number giving us the following, simpler pseudo code or flow.

  1. For each number, starting at 1 and ending with 100
  2. If the number divided by three has zero remainder, add it to the ‘output’.
  3. OR If the number divided by five has zero remainder, add it to the ‘output’.
  4. Otherwise, do nothing.
  5. After we reach 100, print ‘output’

The more important thing about this is that we recognise the OR, a number that has a remainder of zero when divided by both five and three must not be added to the output twice.

The actual Project Euler first question is as follows:

Find the sum of all the multiples of 3 or 5 below 1000.

To solve this with a programming language it is beneficial to know about modulo arithmetic and the modulo operator, but I don’t have time to go in to this at the moment.

In future I hope to go in to other peoples solutions and how optimization is brought into Project Euler.


March 26, 2010

I had been meaning to read the KickAss comic for quite some time and with the release of the movie I took the jump and bought the graphic novel.

Kickass, for those who don’t know is a comic about a kid who decides to don a lycra suit and mask to fight crime. Gets the crap beaten out of him, and then the story goes on. The comic has been so popular that it has already been made in to a movie that has just been released here in the UK.

In the beginning I found it to be really engaging, the characters were my type of people, geeky, inquisitive and witty.  I, and loads of others I assume, could relate to the comic geekery, the hoarding of comics and wonder at how no one could have tried to be a super hero (which still does beg the question, how has no one done this yet?).

The story progresses quite happily for quite some time and it’s predictable but interesting and new, then, out of nowhere it falls like shit from a plane. ¬†Although I didn’t anticipate the twist I can see it being quite easy to predict and by the end I was pretty annoyed at how it had all gone.

I’m happy to say that the setup for the sequel made me want to vomit and cry with disapointment. I want to start reading it monthly but I don’t to start paying for it, I just hope that Nemesis is a little better.