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

Project Euler’s first problem:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

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

By brute force I can write code that checks every number below 1000 to see if it’s divisible by 3 or 5, if it is then add it to a running total.

I’m using Visual Basic (VB.Net 2010 to be precise). This might seem a little odd for an Ubuntu member but I’m thinking of trying MT264 (Designing applications with Visual Basic). Open University students qualify for Microsoft’s Dreamspark promotion, so I got a copy of Visual Studio 2010 Express to try it out. Besides, I’m at work so haven’t much choice.

Starting off with a “Console Application” template:

Dim beganAt As Date = Now
Dim total As Long = 0
' Repeat a thousand times
For counter As Integer = 1 To 999 Step 1
     ' Check if the current integer is divisible by 3 or 5 and
     ' if it is then add it to our total
     If (counter Mod 3 = 0) Or (counter Mod 5 = 0) Then
          total = total + counter
     End If
Next
Dim endAt As Global.System.TimeSpan = Now.Subtract(beganAt)
Dim took As Integer = endAt.Milliseconds
Console.WriteLine(total.ToString + " in " + took.ToString + "ms.")
Console.ReadKey()

Running this code and clicking the button we get the answer 233168, which Project Eular confirms. Code must run in less than a minute, the timer shows less than a millisecond.

I can see another way to do this, by using two for loops – one in steps of 3 and one in steps of 5, adding the counter to a total for each. I don’t know if this offers a significant time saving, so I re-ran the original code, making the loop repeat a million times and it completes in 375ms. I can’t see any value in going any further.

Finally succeeding?

I read an article by James Somers at The Atlantic called “How I Failed, Failed, and Finally Succeeded at Learning How to Code“. I’d encourage anyone with an interest in learning to code to read it – he discusses how computer programming is an excellent learning experience but that his own experiences have been tempered by poor instruction, particularly from books. He goes on to discuss how Project Euler became the titular success.

Euler provides a series of programming challenges of increasing difficulty, as the student solves each in turn they gain experience of what does and does not work as well as confidence in their abilities. Importantly, the student is also applying programming to practical problems (if you’re a mathematics student) from the outset.

I’ll post my solutions here as I go. I’m aiming to do one a day but I’ll see how I get on. Not sure what language is best to get on with, Python is popular in open source circles but most of my courses are based around Java.

 

Completing BSc (Honours) Computing and IT

With ten years remaining in my contract and the government’s intentions unclear, I’ve decided to get my finger out and focus on completing the BSc (Honours) Computing and IT (B62). It can use 120 points from four completed modules - M150T175MST121 and M255 as well as 30 points from MS221, which I have already started.

At level two I’m taking two courses on top of MS221 which I intend to study concurrently, so as to be half way through by the end of next year:

  • T215 - Communication and information technologies (60)
  • MT264 - Designing applications with Visual Basic (30)

Leaving 120 points at level 3:

  • M359 - Relational databases: theory and practice (30)
  • M364 – Fundamentals of interaction design (30)
  • M366 – Natural and artificial intelligence (30)
  • TM470 – The computing and IT project (30)

Running

Since I got back at the end of May I’ve been running further, increasing to around 22 miles a week.

Annoyingly, I’ve picked up what I suspect is Tendinitis although I’m not sure which of the tendons it is in my left foot. I’ll make a doctors appointment tomorrow – assuming I see someone this week, they’ll no doubt prescribe Ibuprofen and shunt me to physiotherapy.

I’ve kept running but reduced the distance, started doing specific stretches and using cold packs to reduce any pain. I’m going to re-lace my shoes and see if it makes a difference.

Black Ops “Strict”

Odd solution to an irritating problem – Black Ops say “Strict” in multi-player, even with “Open” NAT. Load Modern Warfare 2, go to multi-player on-line up to the point where you choose the game type and eject the disc using the button on the front of the PS3. Insert Black Ops and load it, go to multi-player and you will be open.

I have no idea why this works, I got it off a forum post. I have tried putting the PS3 in a DMZ but it doesn’t work, so it’s not as if the game uses non-standard ports – it’s just bugged. It only needs to be done once each session – you can play something else and reload Black Ops as long as you don’t reboot.

Black Ops is an OK game, it’s not the best FPS and the single player is woefully short (with a very poor story) – its multi-player where the fun is to be had. With the latest DLC out on the 10th June, it’s a shame that Activision and Treyarch can’t get it together enough to sort this out. The truth is though that until we stop buying DLC, there’s no incentive for the publishers to fix bugs.

TU100 Café

I’ve submitted T175‘s EMA and I don’t mind saying its a relief. Although not a difficult module, the OU changed the Computing degree structure introducing TU100, replacing T175 and M150 (which I did several years ago). Along with MST121 I had thought that I had my level one courses out of the way but with the changes, I needed to take T175.

This course used Moodle forums rather than FirstClass. This seems to have been a lot more accessible to new students and the Café in particular has proved popular. The Open University have kindly asked me to be one of the moderators in the Café on TU100. It came as quite a surprise – I hope I make a good job of it!

Calculators

I’ve just started a maths course (MS221 with The Open University). I completed MST121 with a cheap Casio FX991 calculator (it cost about £15).

The time has come to buy something a bit more, well grown up. I’ve been looking at offerings from TI and HP. I’m kind of leaning towards an HP 50g. I can’t make up my mind so I thought I’d throw it out there and see what people recommend. The course says any calculator is allowed provided it doesn’t need plugged into the mains, doesn’t have a QWERTY (or local equivalent) keyboard and can’t communicate with other calculators.

Ideally it should be able to connect with Ubuntu – the HP has an SD card but I don’t know about TI.

 

I killed my PS3

I’ve been playing the brilliant “Assassin’s Creed – Brotherhood”. So much so that I’ve killed my PS3 – it now overheats and turns itself off after about three minutes (if its booted from cold), beeps three times and flashes the power light. Mind you I’ve had it for about four years.

I bought a new one (surprised that the hard disk size going up seems to have reduced any price decreases over time).

Seems like a faulty fan – sounds like a bearing grinding. Anyone any experience with them?

Don’t fix it, censor it

The Security Research Computer Lab at Cambridge University posted an article about industry response to a fundamental flaw in the “chip and pin” system in February. The paper, by Omar Choudary (a PhD student), highlights a flaw in the standard that permits the use of any PIN number. The University passed it to industry two months before publishing.

Now, some eight months later, the only bank known to have addressed this is Barclays. Instead of addressing the issue, the bankers’ trade association feels the best course of action is to tell the University its being irresponsible [pdf] in publishing the information! Given the Streisand Effect, is that not trying to close the stable door after the horse has bolted? The University’s response is an emphatic no, at the moment.

It is interesting that the UK Cards Association feels an offence was committed in proving the vulnerability. I would have thought they’d welcome the information, given their front page statement:

We inform and engage with stakeholders to advance the industry for the ultimate benefit of our members’ consumer and retail customers. Our work includes preventing card fraud, contributing to legislative changes, collating industry statistics and developing industry standards and best practices.

Linux is not a get of jail free card

I’ve been having line problems with my ISP – British Telecom. To cut a long story short we see a 75% speed drop, phone BT, jump through umpteen hoops and they reset the profile at the exchange. The fault is with the line and it’s intermittent.

That doesn’t really bother me. The customer support agent told me to use BT’s speed diagnostic tool. Now aside from why their tool would be better, its not really an option as its a poorly written Java applet that doesn’t seem to work with Firefox or Chromium in Linux. Now I dare say I could get it to work but why spend the energy? When I mentioned it to the agent, he told me BT doesn’t officially support Linux and helpfully suggested I keep a Windows laptop handy.

Are you kidding? Keep a Windows laptop handy? There are reasons why I use Linux, there are reasons people use Macs and Windows too – they chose to. What the hell has that got to do with my ISP? I have no software from them, it’s a wireless access point they provide. Do you know what operating system it runs? Linux.