Thursday, December 1, 2011

Enigmatic Code

For the past few years I've been treating the weekly Enigma puzzles in New Scientist magazine as a programming challenge. I started writing programs to solve the puzzles in Perl (and occasionally C, when speed was all important), but more recently I've been coding up solutions in Python.

Now, I've decided to set up a blog to share programmatic solutions to Enigma puzzles. I opted for a WordPress blog, as I couldn't get Blogger comments to accept pre-formatted code. Whereas WordPress comments let you use HTML <pre> tags.

I aim to add new puzzles (and solutions) as they are published (usually on a Thursday in the UK), and also retroactively add old puzzles that I have coded solutions for, or found from the New Scientist archives on Google Books, as time allows.

If you'd like to join in, please visit the Enigmatic Code blog.

Monday, September 26, 2011

Dice Emulator

The Merry Game of Floundering
The other day Caroline came home with a charity shop find - The Merry Game of Floundering* - which I'm sure we used to play as kids (although my Mum claims never to have heard of it).

All the pieces were there with the exception of one of the dice (it needs to two). So rather than search for another die I did what any self-respecting programmer would do, and knocked up a dice emulator in Python.

Thanks to the pygame library and Unicode characters U+2680 - U+2685 I was able to get a program together quickly which we then triggered using the Apple Remote (using Remote Buddy's Virtual Mouse behaviour). Simple as that!

dice.py
The program is presented below. Be aware, though, it makes some assumptions about running on my MacBook. If you're running it on non-1280x800 screen size you'll probably need to change the font sizes, and if you're running on a non-Apple system you'll probably need to change the font for the die characters (or go back to using ASCII numbers, as it was originally), and the location of the sound that is played when the dice is rolled. Also there is some code there to highlight special scores (doubles, and 6 and 1), which are specific to the Floundering game - take them out, or define your own. Enjoy!



[*] While searching for more information on the game I found someone selling a set on eBay as "The Messy Game of Floundering".

Monday, August 8, 2011

Gotta Catch 'Em All

"Fade to Black"
From 6th July 2011 to 7th September 2011 there are 60 decorated gorilla statues roaming the (mostly) Bristol area. (See the Wow! Gorillas page for for details).

We're now half way through their visit and I've managed to collect 53 out of 60. You can see my efforts in my Facebook photo gallery. (Facebook registration not required).

So I'm missing 7:
  • Gorilla 5 ("Sky Gorilla"), Anchor Square, Bristol Harbour.
  • Gorilla 9 ("Willard"), A Marriott Hotel Lobby, Bristol.
  • Gorilla 25 ("Elvis"), Bristol Bus Station.
  • Gorilla 26 ("Hubert"), Holiday Inn, Bristol.
  • Gorilla 29 ("Ape Scape"), Bristol Airport.
  • Gorilla 40 ("Winston"), Avon Gorge Hotel, Bristol.
  • Gorilla 60 ("Guerilla Tourist"), Birmingham(!) Coach Station.
I missed #5 on my visit to Bristol Harbour - I think it must have been obscured by a fairground ride that was there.

I foolishly thought that the Marriott Hotel City Centre would be the one by The Centre, but it turns out that that's the Marriott Royal Hotel, and the City Centre one is at Broadmead (I suppose that's "City Centre" when compared to Bristol Airport or somewhere). So I ended up at the wrong hotel. (Although #9 is in the Broadmead one from today).

I don't usually happen to pass through Bristol Airport on my day-to-day travels, but I might be able to get out there sometime in the next month to collect #29.

But Birmingham seems a bit of a way to go. Although I know the closer I get to completing the set the more I will feel compelled to make a trip up to Brum.

But there maybe a solution. Apparently Gorilla #61 ("Doris") is currently floating around Bristol Harbour on the prow of The Matthew, and was organised too late to make it on to the official maps. So there may be hope of sneakily collecting 60 Gorillas after all.

Update 2011-09-04: I'm now on 59/61 - only #29 and #60 to get!

Update 2011-09-06: I went to Bristol Airport and collected #29 today. 60/61.

Update 2011-09-25: I finally collected "Guerilla Tourist" today, now that he's outside Bristol Zoo and no longer in Birmingham. 61/61.

Monday, May 23, 2011

Apocalypse - Not!

So, the Rapture didn't happen on Saturday 21st May 2011. Still, it's not the end of world, eh?

But it was the end of my venerable Compaq Evo N610c that is so good IMDb didn't want it back when I left. The hard disk failed a mere 7½ years after being replaced. Oh well, it's been doing a good job for the last (almost) two years as a firewall machine with Ubuntu installed and a PCMCIA network card.

I recently retired it from firewall duty (as it's on-board network connection seemed to be playing up, although the problem disappeared once I'd retired it), so it was left acting as a local DNS server and a WebDAV server (for sharing iCal calendars). Both of which I would rather the Time Capsule would take care of - but it doesn't.

I've managed to resurrect it for now using the 160GB drive that I removed from my MacBook when I expanded that, attached to the Evo using a cheap USB enclosure, put another Ubuntu install on it and installed dnsmasq and got lighttpd running as a WebDAV server, and everything seems dandy again.

But I can't help thinking I'd be better off with a proper low power server to do this kind of thing.

Wednesday, March 16, 2011

Javascript Speed Tests

Every so often I think about changing the browser that I routinely use. For the last five years or so I've been using Camino, first on my PowerBook, and now on my MacBook.

Today I decided to try the sunspider-0.9.1 Javascript benchmark on a variety of browsers that I have to hand, and here are the results:

  Camino   2.0.6        3085.3ms
  Chrome   10.0.648.134  319.0ms
  Firefox  3.6.15       1014.6ms
  Firefox  4.0           313.8ms
  Opera    11.01         347.9ms
  Safari   5.0.4         333.7ms

So it seems I am currently using the browser with the slowest Javascript performance (by a factor of almost 10x), and although I've become very used to Camino, maybe it's time to consider a switch (again).

Update 2011-03-22: Added in Firefox 4.0 (which is the current leader, and means that all the alternatives are about 10x faster than Camino in this test).

Thursday, February 10, 2011

Top Time Machine Tip

Here's a Top Tip for those using Apple's Time Machine...

If you are backing up multiple computers to a single Time Capsule, and one of the machines decides there isn't enough space to complete a backup, try compacting the other backups - especially if they are quite large.

Open a Terminal and the following command:

# hdiutil compact /path/to/backup/sparse/bundle

I did this on the backup of my machine, when another laptop was deleting old backups trying to make space, and it freed up over 90GB of space. Plenty enough to allow the other machine to complete it's backup.


I turned off automatic backups while it was running - remember to re-enable them afterwards.

This is something that Time Machine will run itself if it's runs out of space, but it will only compact the backup for the machine that it is running on, so if there is a potentially large amount of free space in a backup for a different machine that won't get reclaimed. Instead the first machine will start sacrificing it's older backups to make space.

Note: I'm running Time Machine on OS X 10.6.6

Wednesday, February 2, 2011

These Boots Are Made For Walking

How long should a pair of walking boots last?

Berghaus - worn out after 6 months.
In March 2010 I bought a pair of Berghaus Explorer Trek lightweight boots, and was a bit disappointed when the soles wore out after only six months of use. However, thinking about it in a bit more depth - six months is 26 weeks, I probably walk around 20 miles a week with the dog, and so the boots could easily have gone for 500 miles or more before the soles wore out - at a cost of around 17p/mile (interestingly a similar amount to what petrol costs are for the car).

This compares fairly favourably with my "proper" walking boots (Meindl Burma Pro), which have, by my reckoning, covered around 650 miles in the last 7 years (albeit quite tough miles in some cases). But given they cost almost twice as much as the lightweight boots they are currently coming in at around 25p/mile - although they are still serviceable, so I expect them to clock up a few more miles. But it is sobering to think that they will have to do almost 300 more miles to reach an equivalent economy to the lightweight boots.

Zamberlan Trek Lites - 480 miles.

My previous walking boots (db Mountain Guides) covered around 660 miles, to come in at 18p/mile (although they had been replaced early in their life, when the eyelets in the original boots failed). Eventually they became too uncomfortable to wear, rather than actually failing.

Before that I had a pair of Zamberlan Trek Lites, which although they only managed 480 miles before one of the soles started coming off, also came in at around 19p/mile.

Hawkins Kestrel - 5p/mile.
But all of these have some way to go in order to beat my first pair of boots - a pair of Hawkins Kestrel boots, bought for £23.50 in 1986. They managed 550 miles (including the Wolds Way, the Coast to Coast and the 10 Highest Peaks in Britain, along with many other walks) before one of the heels finally fell off while backpacking on Beinn Challum, clocking in at under 5p/mile.

So looking back, it seems that 500-600 miles is about par for the course for a pair of walking boots, and just because I covered that distance in several months rather than several years I shouldn't feel that the Berghaus boots have underperformed.