Tuesday, 28 April 2009

Broadband woes and customer service triumphs

WirelessRouterMy Broadband router died the other day. One night it worked, the next morning – caput! No lights on the front panel, no response even when I prodded the reset button with a pen. Our house seems to be an unhealthy environment for electronics. I blame my wife: when she was at university, she could crash a computer just by sitting down and putting her hand to the mouse.

But my luck was in. This was a Belkin router, and it came with a lifetime guarantee – and not a gnat’s lifetime either, as it turned out.

I suspected a fried power supply, so I got chatting to technical support (Live Chat does an excellent of rendering an Indian accent intelligible to British eyes!), intending to ask them to replace it. I got more than I bargained for.

Having cleared the hurdle of First Line support, Second Line agreed that they would give me a replacement – of the whole router. In fact, they would give me an upgrade, since the model I had was obsolete. And to top it all, they emailed me a postage-paid label by which to return my old router.

Now get this: I bought the router for £20 second-hand from a colleague more than a year ago, yet that didn’t concern Belkin – at no point did they ask for so much as a whiff of a proof of purchase.

The router duly arrived, I plugged it in, and – no connection. I borrowed a friend’s router – no connection on that either. Clearly my line had rotted from lack of use.

That was when I discovered the magical iPlate from BT. It’s a widget that costs less than a tenner, that really does install in minutes (on top of your home’s master socket), and it brought my line back from the dead. It works, I’m told, by cutting out the bell wire (used, in the olden days, to ring your phone’s bell, but now defunct and the cause of much interference on the line). My download speed is pretty much as it was before, but my upload speed has almost doubled!

So now I don’t even have dead Broadband as an excuse for not updating my blog in over a month!

Friday, 27 March 2009

Project Euler 21: Getting friendly with the Amicable numbers

I’ve remarked before that to Mathematicians, numbers aren’t, … well, they’re not just numbers. Numbers have personalities. Whilst some are deficient, there are others which are aspiring, and a few who are actually perfect;  half of them are rather odd, some downright weird. Of more concern are the odious and evil numbers, especially those that consider themselves untouchable1.

But today we’ll look at a more friendly subject: the amicable numbers. What is an amicable number? Let’s get mathematical and define a function d(n) to be the sum of all proper divisors of n (a proper divisor of n is any divisor of n less than n). Then an amicable number a is one which has a friend b where d(a) = b and d(b) = a (note that we don’t allow a to be narcissistic and count itself as a friend). If you do the math (or these days, more realistically, the google search) you’ll find that the first pair of amicable numbers is 220 and 284.

Amicable numbers have been studied since Greek times: the Pythagoreans in particular credited these special numbers with mystical powers. They’ve even by tried out as a kind of mathematical aphrodisiac:

El Madshriti, an Arab of the 11th century, experimented with the erotic effects of amicable numbers by giving a beautiful woman the smaller number 220 to eat in the form of a cookie, and himself eating the larger 284!

My sudden interest in amicable numbers was driven by strictly mathematical desire  - to solve Project Euler 212. The problem simply asks us to find the sum of all amicable numbers less than 10000. And in fact, the solution to the problem pretty much falls out of its definition.

First, I’ll borrow a function from a few problems back that lists all the divisors of a number:

public static class NumericExtensions
{
    public static IEnumerable<int> Divisors(this int number)
    {
        return (from factor in 1.To((int)Math.Sqrt(number))
                where number.IsDivisibleBy(factor)
                select new [] { factor, number / factor }).Concat();
    }

}

With that, the answer is straightforward:

[EulerProblem(21, Title = "Evaluate the sum of all amicable pairs under 10000.")]
public class Problem21
{
    public long Solve()
    {
        Func<int, int> d = n => n.Divisors().Sum() - n;

        return 	(
				from a in 1.To(10000)
                let b = d(a)
                where a != b && d(b) == a
                select a
				)
                .Sum();
    }
}

As always, full code is available on the Project Euler Code Gallery page.

Footnotes
  1. If you want to learn more about number personalities, see this catalogue.
  2. Thanks to Bela Istok who sent me a nice functional solution to the problem, which prompted me to think about how I would solve it myself.

Tuesday, 17 March 2009

Functional Fun on Twitter

I’ve just taken the plunge, and started tweeting on Twitter, user name @samuel_d_jack.

There have often been times when I’ve been intrigued or amused by something, but haven’t felt sufficiently creative to make a full blog post out of it: micro-blogging on Twitter seems to be the ideal solution.

I’ve added my Twitter feed to the right-hand side of my blog; and if you don’t find my drivel to be too deleterious you can even subscribe to the RSS feed.

Wednesday, 11 March 2009

Leaky Abstractions at the Petrol Pump

Even as a software developer, I'm still ocassionally surprised when events remind me that Spolsky's Law of Leaky Abstractions applies to hardware as much as to software.

Here's an example from my holidays last year, when I went to fill up with petrol (how can you Americans call it gas when it's clearly a liquid?):

Any non-technical motorist who peered at the tiny writing on that blue screen and read "DRIVER_ERQL_NOT_LESS_OR_EQUAL" would surely feeel that he's being blamed for the failure, but what did he do wrong? Sounds like he failed some important existential test.

I'm clearly not the only one who enjoys spotting BSODs in the wild: Miguel Carrasco has put together a Blue Screen of Death Top Ten. And on Gizmodo they have a snapshot of a BSOD that appeared in the Stadium during the Opening Ceremony at the 2008 Olympic games.