Archive for July, 2010

Project Euler: Problem 2

Tuesday, July 27th, 2010

Problem 2 of Project Euler is:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

This code (in Delphi 2007) finds the solution in under a second:

procedure TfrmMain.Problem2;
var
  term1, term2, nextTerm :int64;
  numTotal :int64;
begin
  term1 := 1;
  term2 := 2;
  numTotal := 2;
  nextTerm := term1 + term2;
  while nextTerm <= 4000000 do begin
    term1 := term2;
    term2 := nextTerm;
    if not odd(nextTerm) then inc(numTotal, nextTerm);
    nextTerm := term1 + term2;
  end;
  ShowMessage(IntToStr(numTotal));
end;

(more…)

Project Euler

Sunday, July 25th, 2010

Some time ago I came across Project Euler, which hosts a collection of mathematical problems which are primarily designed to be solved by computer programming.  From the web site: 

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems. 

As at today there are 299 problems on the site, and I thought it might be an interesting task to try and solve some of them, outlining my reasoning as we progressed through them. I will be using Delphi 2007 (Pascal) to work through them but hopefully the code should be easy to convert to other languages. 

(more…)

Java file handling

Thursday, July 22nd, 2010

I’ve recently bought myself an Android phone (the Sony Ericsson Xperia X10).

I am very pleased with the phone and decided to convert one of my freeware apps to run on it.  The app I am converting is secureIT, a notepad utility which can be used to manage passwords and other sensitive information.

(more…)

Predator: still waiting for a sequel

Wednesday, July 21st, 2010

I’ve just returned from watching Predators, the third film in the Predator series.

The first film (starring Arnold Schwarzenegger) was a gripping story with (for then) state-of-the-art special effects. The second installment (starring Danny Glover) was a disappointment, so I was hoping this new film would recapture the magic of the original. Sadly, it does not.

(more…)