An interesting puzzle - see http://blog.takeit.se/woups-turns-out-this-was-a-hard-problem