Lightly Seared On The Reality Grill

Random expat geekery from The Low Countries

Browsing Posts in Self Indulgence

Thirty-One

No comments

I started this year with the intention of blogging more regularly. Specifically, I wanted to try to put up at least one post a day. Surprisingly enough, once month in, I am managing to do so.

It turned out to be a lot easier than I expected and, gratifyingly, I have found that I am spending a lot less time on various social networks and a lot more time doing and reading stuff that actually interests me. I think the take-home point here is that, while a lot of social networking activity does provide the instant gratification of an immediate response, it is also very easy to allow it to become too much of a time sink.

I do prefer the longer, slightly slower, approach that blogging necessitates. Counter-intuitively, I have also found that this is a lot less time consuming – and a lot more satisfying – than trying to express myself in the shorter form encouraged by social networks. I think there are a couple of reasons for this.

Firstly, and I have to acknowledge that this is not a heavily trafficked blog, blogging doesn’t feel like a live conversation in the same way that microblogging does. As such, I don’t worry about how quickly I release or respond to comments and an quite happy to engage in conversations that develop more slowly and (hopefully) more thoughtfully.

Secondly, and related to the first point, is the fact that I am increasingly recognising that there are some issues which I do think are important but about which I have nothing to add. While it is easy to tweet, dent or plus a link to some news article or online opinion, seeking to actually write a blog post is pushing me towards focusing more actively on things about which I actually have something to say.

That’s not to say that social networks are a bad thing and I have gained a lot of entertainment from them, but I do think it is useful to recognise just how much of a time sink and an echo chamber these things can be.

I started blogging way back in December 2002 and, for a long time, I got a great deal out of it. Over the last three or four years, I have blogged less as I became increasingly distracted by various social networks. I’m not about to abandon social networking – identi.ca is a great place to talk to smart people and Google+ is a handy way of posting links about which I have little to say – but I do find that blogging works best for me and is something that I am finding increasingly easy to maintain.

flattr this!

TFSMIF

No comments

Those were angry clouds I drove through to get home tonight.

flattr this!

The sky was a gorgeous red this morning as I drove into work, and this snap from my phone completely fails to capture it.

I was, of course, intending to post this this morning but things have been a little hectic today. So enjoy the post-lunch lull as much as I hope to.

flattr this!

It’s been pointed out to me that the contact form on this site wasn’t actually working. This is now fixed and you are free to message me to your heart’s content. As long as it’s not too much.

I shall also take this opportunity to mention that if I do break the contact form again, you can also get in touch with me via either Identi.ca or Google+.

flattr this!

Five days into 2012 and it’s cold, wet and windy. Much the same as any northern January, really but we all made it one more time around the Sun and that’s as good an excuse as any to celebrate. And celebrate we did.

The start of a new calendar is also, for many people, a time to make unkeepable resolutions. This is something I try to avoid – unkeepable resolutions are things I make throughout the year – but one thing I do want to try to achieve this year is to keep this blog regularly updated. My target, at the moment, is to try and manage one post a day on whatever subject happens to catch my interest.

I don’t expect anyone to find all of it interesting to them and most people, I am sure, will find none of it to be particularly interesting. But that’s okay because I’m doing this for me.

And since I’m sitting here, getting all meta and stating the obvious, I have also been playing around with this blog’s theme options. It’s now a lot lighter and a little greyer and I am quickly getting used to it.

flattr this!

While in the process of tidying up some of the pages on here, I noticed that the About page is not as clear as it could be. Specifically, the last paragraph, in which I get a bit techno-political, is a bit garbled. Or was.

It’s now updated and, for the sake of transparency, I have replaced this paragraph:

The more time I spend using Free and Open Source and Free software (FOSS), the more convinced I become that this is the right way of doing things – not only on a technical level but also on a political and economic level as well. Proprietary software locks you into a platform and deliberately makes it difficult to move, regardless how decrepit that platform becomes. FOSS, on the other hand, as well as (and possibly more importantly) Open Standards, prevents this sort of lock in and puts the control of an individual’s environment back in the hands of the individual.

With these ones:

The more time I spend using Free and Open Source and Free software (FOSS), the more convinced I become that this is the right way of doing things – not only on a technical level but also on a political and economic level as well. Proprietary software locks you into a platform, which becomes increasingly painful to move away from, and forces you to remain dependent on a single supplier. This combination of pain and dependency allows the first (or biggest) supplier into a market to behave like (and become) a monopoly, stifle innovation and gouge the consumer.

FOSS, on the other hand, encourages openness. This allows developers to innovate on the basis of the best ideas already out there rather than having to constantly reinvent other people’s wheels. The openness of FOSS development also means that you can know what your applications are doing and, if you’re not happy with any of it, easily identify the people responsible and ask for improvements.

You can also submit improvements, of course, and I still find it surprising that so many businesses continue to fail to recognise the time and cost savings that this simple fact can accrue.

Possibly more important is the fact that FOSS projects tend to be very keen on adopting open standards and it is the adoption of open standards that protects you, me and everyone else from being locked into proprietary monopolies. For a long time, I tended to think about open standards in terms of data formats – if my data is in an open format, I will always be able to find a program that can handle it. But the more I look at the rise of walled gardens online, the more convinced I become that open standards need to be aggressively promoted as the only way to connect to the internet.

I don’t allow comments on static pages so if you want to respond to any of this, feel free to do it here.

flattr this!

Also known as: Project Euler problem 15

Also known as: A week to understand, a minute to implement.

The problem:

Starting in the top left corner of a 2 x 2 grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a 20 x 20 grid?

To start with the simple observation first: Any route through an m x m grid can be expressed as a sequence of Rs and Ds where R is right and D is down (the without backtracking condition ensures that you can’t go left or up – this simplifies things somewhat).

The second observation is that each route must be exactly 2m steps long (m steps to the right and m steps down).

So the problem that needs to be solved is: How many ways can you combine m Rs and m Ds?

It turns out that this is a combination problem which Wikipedia handily defines as a way of selecting several things out of a larger group, where order does not matter. The larger group, in this case, is all 2m steps and the several things you want to select are the k possible combinations of R (or D). The Ds (or Rs) don’t matter because you know that they have to populate the m remaining slots in the path.

A k-combination of a set S is a subset of k distinct elements of S. If the set has n elements the number of k-combinations can be expressed as n! / k!(n - k)! as long as k<=n.

Implementing this was a doddle and, for bonus points, my solution should work for any rectangular grid.

flattr this!

Also known as Project Euler Problem 12.

This is the first one that has proved to be a bit of a challenge for me, and one that forced me both to do a bit of research and to take a look at the efficiency of some of my functions.

First the problem:

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

Let us list the factors of the first seven triangle numbers:

1: 1
3: 1,3
6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

Obviously a brute-force approach is not going to work in this case. Since I already had a function for generating prime factors, which I developed for Problem 3, I started thinking about whether it was possible to calculate the total number of divisors of a number based on its prime factors.

It turns out that it is.

The factorisation of a number can be expressed as: P1^F1 * P2^F2 * … * Pn^Fn

And the total number of divisors is: (F1 +1) * (F2 + 1) * … * (Fn + 1)

For example, 28 can be expressed as 2^2 * 7^1 so the total number of divisors is (2 + 1) * (1 + 1) = 6

Or, 36 = 2^2 * 3^2 so the total number of divisors is 3*3 = 9.

Coding this formula was pretty straightforward. Unfortunately, the resulting program ground to a halt once I started looking for more than 200 divisors – and this has had me stumped for a couple of days. I knew my reasoning was sound and I could see the program generating correct results for small numbers of divisors, but I could not figure out why it didn’t scale.

It wasn’t until I went back to look at the efficiency of my factorisation function that the following insight hit me: You don’t need to test whether a number is prime if you can guarantee that your loop will only look at prime mumbers.

This insight resulted in the following, much more efficient, function:

def Factorise(integer):
	factors=[]
	index = 2
	while integer > 1:
		if integer % index == 0:
			factors.append(index)
			integer=integer/index
		else:
			index += 1
	return factors

Starting with an index of 2 (the lowest prime) I simply divide the integer by the index until I get a non integer result. Then I increment the index and start again.

Because the function repeatedly divides out each factor, integer/index can only return an integer result if index is prime.

With this approach, I was able to solve the problem in about half a second.

flattr this!

Good Morning

No comments

It’s not every day that I see a striking sunrise and am close enough to a reasonable parking spot.

flattr this!

Decathlete

No comments

I don’t really have anything more to say about Project Euler, but I am quite pleased with myself for having unlocked the second progress award.

I can now claim to be a Python programming Mathematical Decathlete and the 14170th person to unlock this achievement.

I have to admit that my maths were more than a little rusty when I started having a go at these problems but, in figuring out how best to attack these problems, I have both remembered and learned a huge amount. I have also, over the past few weeks, gained a much greater appreciation of just how elegant many mathematical concepts can be.

flattr this!