## The Midlife Geek

### Ramblings of a middle aged engineer, runner and open source enthusiast

#### Tag: MST121

I’ve had nothing but problems with this TMA, the latest being Word refusing to open my solution document. Last time I bother with that, its a lot easier just to write it all out by hand.

I hope I can remember the material for the exam. Being allowed the handbook and working through past papers will probably be enough but I’ve found MS221 a big jump from MST121, frankly it’s put me off level three but you never know.

My problem is that I just can’t spot patterns so have great difficulty making conjectures. There’s a conjecture question in the first TMA and although I’ve got the Mathcad sheet all set up, I can see an approximate connection but can’t think of a way to formalise it.

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.")

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.

﻿﻿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.

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)