Monday, 30 December 2013

Christmas Puzzles


The family coffee table this Christmas saw many retro toys and puzzles come and go across it's veneered wooden top; table-top crazy golf, rubber band cars, a plastic miniature Connect Four and even a couple of Transformers Robots with realistic firing missile launcher bits!

Tetris jigsaw, and, if you look closely - PacMan Socks!
Particularly exciting in my Christmas present pile was an official Tetris jigsaw puzzle.  One hundred cardboard pieces of rainbow-coloured tentromino shaped fun.  It'd been ages since I'd last done anything approaching a real jigsaw puzzle, often a Christmas cracker would contain a small token effort, but they are always a disappointment, so to have a medium-sized bite of an incredibly intricate pattern of tiled pieces was the perfect start to my Christmas morning.  I managed to get my organisational skills into place, first identifying corners and constructing edges. Then, upon spotting that there were only two types of non-edge piece, quickly categorised the remainder and could work my way in from the outside.  The puzzle was quickly solved, though some patience was required to match up the colours on the tabs and surrounding the blanks. But, as the number of pieces put into place became greater, and the time to hunt became less, the gaps became smaller, the picture clearer, until finally the puzzle was completed with a jubilant and resounding "done!".  Then the Smirnoff vodka-flavoured chocolate truffles were started in celebration.

A family Christmas wouldn't be a family Christmas without my brother and I wading through some of the latest video-game releases.  Between Assassin-pirate pilfering, heist holding hooliganism, Roman risen revenge and zombie apocalypse antics you would think there to be little time for much else.  Except a rather nice puzzle game named Fez that, despite my best efforts, took up a rather large chunk of my holiday time.  We'd recently watched "Indie Game: The Movie", in which the development of the game features heavily, and where curious about what it actually entailed.   Running around a 2D-3D puzzle world searching for yellow cubes mostly.  The puzzle element of the main game was entertaining, with a particularly nice art style and some really stunning mind-bending puzzle/lateral thinking/realisation moments.  However the game also featured it's own set of meta-game puzzles, necessary to find the blue "anti-cubes".  As a child I would have loved transcribing and translating the in-game language to solve these elaborate puzzles. Unfortunately now, as a time limited, cynical adult, I could appreciate their beauty, depth and execution, and could also reflect on the fact that I no longer have to have solved said puzzles by myself (or call up some extortionate tips hot-line while my parent's weren't looking), because there's a million YouTube videos and web-based walk-throughs to save me from having to work out things that "I know how to work it out, but guess what, I don't need to!".

Finally, there was one other puzzle that occupied a lot of my time.  To go with the plastic miniature Connect Four, there was also a mini Draughts, Chinese Checkers and, most interesting to me, English Peg Solitaire.  I spent quite a few hours click-tap-clicking away at the pieces of this latter game, trying to understand the patterns and the dance the pegs and holes could form.  Eventually I realised that it'd require a fair amount of thought (or days of trial and error) to get to a solution.  Plus, I think I was starting to drive my family mad with the constant click-tap-click-tap-click, "oh grrr" coming from the sofa.  So, on Christmas day, after finishing the jigsaw (and celebratory vodka-truffles), I broke out the laptop and knocked up some code to find and then draw out step-by-step instructions.  Once followed and the game solved, I did a bit of reading up on Wikipedia, the problem has a lot of interesting properties including memonics for helping to remember a nice solution based around composite moves.

My step-by-step graphical solution follows, though it's not an intelligent or minimized one, just the first that my naive solving algorithm spat out.  The Haskell code to do this is on-line for the really interested.


Saturday, 30 November 2013

Quackers

Argh - the last month has flown by, and I've not found the time to write a real post.  (Have lots of ideas for things planned though - just need to actually sit down and write something!).  In the meantime, here's some rubber ducks distracting me during my day...(also, I want one of these machines).



Thursday, 31 October 2013

A Deck of Cards: Part I

The summer between finishing my degree and starting a PhD left me with a whole lot of time with nothing to do.  The last time this happened (the summer four years prior between A-Levels and University) I invested the time in "learning" to program (this was a time when I thought Java In A Nutshell (3rd Edition!) and  Borland JBuilder were the best thing since sliced bread), ready for a new hobby, course and ultimately my "inevitable" (hah!) career four years hence.
Second time around, and I wanted to spend the time learning something radically different that might be useful when interacting with people, and so decided that this would be the summer that I learned all about card magic.  In retrospect, any sensible person in my position would have gone backpacking round South America, but (as I'm sure I rationalised it away at the time) at least when I decide to go take my backpack and "find myself" in an Inca ruin, I'll be able to entertain any fellow travellers with some half forgotten slights, ill timed patter and misjudged misdirections.

So, learning card magic, where to begin?  Well you need something to learn from - back then it was a book, something to practice with - a deck of cards, and some people to practice learned tricks on - family, friends, and a mirror.  Note the singular, a book, a deck of cards (a mirror...).  The point was to learn tricks and to entertain others.  You can do all this with any standard deck of 52 cards* and one book (The Royal Road To Card Magic).  Unfortunately, I got a bit obsessed with card magic books and, separately, collecting decks of cards.

Card magic books are fascinating -

A spring flourish, beautifully illustrated in Royal Road, brought to life by yours truly.

Out-take!
- the really good ones I own (Royal Road mentioned above and The Expert At The Card Table) are written in an olde-world english with charming hand-drawn illustrations of the slights.  To read them is to be drawn into a secret world of misdirection, manoeuvres, patter and handed-down practice.  The author of the Expert At The Card Table had written a book of so closely guarded secrets that the identity behind his pseudonym - S.W. Erdnase - is still a mystery.  Many look to it's mirrored form, E.S. Andrews, as a clue.
Regardless, Erdnase gathers you round, as though you were a small child, and in hushed tones patiently explains his treasures, one step at a time.  The slights and techniques needed to manipulate the cards are explained first, and then, once you have practised hard enough, you can advance to the second half - the tricks - and glue together hard earned muscle-memory manipulations with patter (what you say), and timings, off-beats, smiles and laughs in order to build up a wonderful effect - the impossible event you hope to build for your participants and audience.

Olives to start, Fresh Lemonade and
Skinny with Cheese as main,
and then Mint Tea for dessert.
Many of the mechanical techniques I still play with, and have a few favoured mini training routines of false shuffles, cuts, deals, lifts and shifts (moving entire blocks of the deck across each other) that I'll find myself doing whenever a deck of cards is in my hands.  Actually just a single card sets this behaviour off, as anyone who has ever been to Byron's Burgers with me will know.  A nervous habit I picked up from passing the time on long daily train journeys to and from Uni during my early PhD years.
Aside from the physical mastery, there are also many other mental skills to be learned.  Rote memorization of 52 cards in order can set up some very powerful magic, as-well as peg and linking memory tricks used by the Nikola card system to quickly do location maths in a stacked deck.  To this day I still imagine the Jack Of Clubs as a Bartender holding a Mug (M = 3, g = 9, position 39), or the Six of Diamonds as some Doped  (D6 = Dp = Dope) Ale (l=1, position 1).
Around the same time, I was also a bit of a Derren Brown fan (I'm sure the two interests played off each other), and I managed to get hold of his books aimed at the magical fraternity.  The card tricks contained therein were way beyond my ability, but his essays on performance technique were incredibly useful (to this day I partially judge the interest in my lectures by the amount of coughing that can be heard.  If it's a lot, then I either need to slow down and start again, ask a question, or take a break, as people are getting bored), and on building an effect that connects with the participant as opposed to leaving them wondering "how did you do that?".  The answer is carefully, with a caveat of it's very hard to do.

The problem with magic, and the reason I never really stuck to it, is that deep down it is incredibly deceitful.  A some point, you start lying to and misleading the person you are entertaining.  You deliberately leave clues to throw them off the scent.  When dealing with a magician you have to believe that everything - every word, every motion, every joke, every look, every shrug - has been rehearsed, scripted and put into place.  They'll build up a world where the only obvious solution is so complicated that it's impossible (the card must be heat sensitive!) and you'll miss the fact that, actually, it has to be done simply, and so simply that you won't see it.  In fact, you don't see the simple solution because if it was done that way, you would feel cheated - and that is a feeling you want to avoid, so you don't even consider it.

Magic and mirrors, me and myself as my beautiful assistant.
The (lovely/gorgeous/stunning/artistic/narcissistic) picture of me left is (perhaps?) a(n attempt at a) great example.  It's impossible right?  It's not photo-shopped (it really isn't), and yet there's me, holding a 5 of spades, looking at me in a mirror, also holding a 5 of spades.  Yet both cards are facing the right way.  I must have used a second mirror? or a sticker on the glass? or maybe the real me is the one in the background and the foreground is a trick with a glass plane? Think of the feeling you're experiencing right now.  Curiosity? Wonder? Frustration?  Intrigue?  The next sentence will grant you deflated irritation and you won't believe that you felt what you're feeling right now.

Or, maybe, I'm just holding two cards back to back, and one of them is a 5 of spades printed in reverse?  (You can just see the card in the picture below).

How do you feel?

Knowing how a trick works sucks.

One other thing I got from Mr Brown's words was that I wasn't alone in wanting to be a "pure" card manipulator.  While I did spend some small amount of time and money on trick decks and apparatus, for the most part I hated them - preferring to invest my skills into techniques that would work on only normal cards, and not needing to mark or cut or shorten or treat the decks.  What I found easy to forget is that genuinely no-one cares about how you do a trick, they only care about the perceived effect.  (Fair warning, I'm setting up a rather tenuous analogy with writing computer software and users here...).  Getting obsessed with being able to fake shuffle a deck while keeping 5 cards in known locations and using that skill isn't necessarily all that useful if the trick only needs one card moving to the top of the deck.  (In software, you don't need to break out Factories and Dependency Inversion just because you've read a book).  There are some magical effects that are very easy, powerful and quick using specially rigged decks of cards (and there are situations where having  the user able to see or do or test something tomorrow by writing a hack is much more important that spending two months creating the worlds most beautiful code that no-one will ever touch again).
Of course being puritanical with cards (and thus writing nice clean, well designed and abstracted software) has its benefits too. You can easily make magic with anyone's deck of cards, and after a trick is done, you don't have to messily hide short cards (or worry about copy-pasted code).  There are trade-offs, but it is important to remember there is a participant (or user) in the equation who is not supposed to know you just used a Vernon Multiple Shift which took a month to learn (or that their app is based on an Actor Framework because it took a month to learn), they just want to be amazed before they get bored (ditto). (End analogy).

This isn't even close to the
whole collection!
So, away from the lies and deceit there's the decks of cards.  Oh so many beautiful decks, in so many different designs and styles and finishes and sizes and smells.  I ended up collecting these - anywhere I went that sold a custom deck I'd pick up, or any kind of beautiful deck I could import from the 'states I'd clock up ridiculous amounts of import tax on.  And I'd have to have a few of each, one to stay pristine, and one to use.  And a spare 'lest I destroy any cards in a trick.  That after a week of shuffling drills a deck would be destroyed always filled me with a feeling of dread - I just couldn't (actually, still can't) throw any of these cards away.  And so they piled up.  I'm still drawn to them, perfect boxes of light clean rectangles of card, four symbols, two sharp, two soft, two black, two red (or inverted or faded or gilded).

Two new gorgeous decks arrive -
Black and White Artisans by theory11
Case in point, if you were wondering about the random '*' in the second paragraph at the top of this (now ridiculously long) post, the Amazon search to find the link to a Red Bicycle deck came up with a lot of very, very tempting new designs of cards that I don't own, and two of the most gorgeous card designs I've ever seen, that I now do.  Oops.  Even worse, a wider google has made me angry for missing out on this Kickstarter for a stunning Typographic Deck.

I could write more, but my hands really want to play with my new cards, which makes typing challenging!

Monday, 16 September 2013

Maidens and Vampires

A recent pub dinner with a friend turned into a rather geeky trading of logic-and-mathematical puzzles.  I have a couple of interesting ones used for interviewing potential undergraduates, and he has some to help make his somewhere-between-primary-and-secondary age pupils think.

One we spent a while discussing was the vampires and maidens problem.  In short, three vampires and three maidens need to travel from one floor to another of a building, using a lift that can carry up to two people.  Some extra constraints: the lift needs someone in it to move (as my friend pointed out, this problem really would be better stated using a boat and two shores, but I guess all those boats are busy moving cabbages and foxes...), and if any maidens are left alone with a greater number of vampires, they get turned into lunch.  Can you come up with a plan to move all six from one floor to another without breaking the rules?

A verbal discussion of the problem very quickly becomes unwieldy, so it wasn't long until my notebook came out and diagrams were drawn.  Based on the diagrams and discussion, there were several interesting observations we managed to make about the puzzle.  The moves going back from the end are a mirror of those from the start (from the start, one or two vampires, or a vampire and a maiden could leave.  To reach the end, one or two vampires, or a vampire and a maiden could arrive).  It also is really important to track where the lift is when drawing pictures, lest you try and teleport a maiden!

Since I've been reading up and thinking a lot about visualising information for clear explanations recently, I thought it'd be fun to try and apply some of that thought to both the problem and solution.  In reality, it's not a very hard problem once you understand it (certainly it doesn't have a hugely branching state space), but I guess for kids it could be used as a good introduction to thinking about enumerating possibilities, of logically structuring thought about a problem, of exploiting symmetries, and drawing insights. Or something.  I also added in the fun challenge of trying to describe this problem through the medium (tedium?) of poetry.





One note, if you Google for this problem you'll find it's usually stated (e.g. in Dara O'Briains School Of Hard Sums) as from the ground floor to the top floor.  For the dual purposes of having the six actors adjacent to the line introducing them, and to make the third line of the poem work, I switched the direction of travel.

Super-high res versions in-case anyone wants to actually turn them into posters (if you do - I'd be interested in knowing if they were useful!  Assume the graphics are licensed CC-By-SA).

Saturday, 14 September 2013

Paranoia

"You're a skinny mother******, ain't ya?"
Well yes, I guess I am, I thought.  Though right now that's probably the last observation I expect you to be making, given the circumstances.  I roll my eyes and simply point at the open door.  My friendly insulter nonchalantly saunters out, heading down the stairs as I close the door behind him.  Across the closed doorway my flatmate and I share a glance of utter disbelief, before he goes to return the rather sharp 6 inch knife in his hand to the kitchen.

It's weird the things that can mess with your head.  You can do, act or think "normally" every day, and then one tiny, incredibly unlikely thing happens, and you suddenly live in fear of something stupid that will never happen again. This results in you taking preventative measures to stop these things happening again, (even though they won't), and it slowly messes up your life, one newly acquired ritual at a time.

I have a vivid memory from my childhood of watching The Really Wild Show, and being informed by Michaela Strachan (who, Wikipedia has terrifyingly let me derive, would have been 27 at the time, which is younger than I am now!) that just thinking about insects crawling up your legs, or wriggling in your hair, or nuzzling into your ear, is enough to make you want to scratch or itch or scrape.  Since that lesson, I've found myself not too worried when I feel like something is wandering around inside my t-shirt.  I'll still scratch the afflicted area, but rationalize it as arm hair being squished against sleeve fabric or leg hairs and jeans rubbing the wrong way.  But I'll feel slightly smug and intelligent at understanding the complicated science of cloth causing thin hairs to press into nerves in my skin, and pleased that I'm not leaping to paranoid imaginings of something malevolent trying to turn me into lunch.

A few weeks ago, a nice summer morning.  My room is a little hot and I'm sleeping these days under a thin sheet as opposed to a full duvet.  A good night's sleep and I'm a little dozy in the morning.  I move, the sheet slips and I feel a little itch on my leg.  Something feels slightly unusual, but I dreamily scratch and it goes away.  A few minutes later and another itch on the other leg.  Another dreamy move of my hand to my leg. Another scratch and

YEOUCH!

The quiet sunny morning is broken by my yell.  The sheet flies off the bed, and a tiny black and yellow dot obliviously buzzes to the window and bumps into the glass.  Again, and again, and again.  I look at my painful thumb, it's (very slightly) swollen. Ow.

And so, eventually, we find ourselves at the first exemplar of my point.  I have been sleeping terribly recently.  Every shift of the sheet, every tickle of my leg hair, every bit of skin that changes temperature in the breeze from the window.  Every single thing that before would have been a simple scratch is now a battle not to turn on the light, strip the bed and re-assure myself there is no wasp out to eat me.  My smug knowledge that there is no insect has been gone, replaced with the overblown memory of that one time I went to itch and got (very mildly) stung in return.

At this point you might be wondering what my moaning about insects has to do with the me being insulted by a stoned guy at 2am.  Well that night also left me with a different irrational fear.  That of scaffolding.  Or, more precisely, scaffolding erected near to somewhere I'm living.  Like the wasp sting, it only takes one slumber to be broken by the sound of your flatmate rummaging through the knife draw in the kitchen to find something to use in self defence, followed by shouts of "who are you?" "what do you want?" out the French windows to an incoherent and rather smelly mass that found its way onto the balcony, for you to become scared of something.  And my mind decided to lock onto the tubular and wooden tower that had (most likely) given the guy access to our third floor exterior.

Back in the present, next door are having some work done, and a scaffolding tower has gone up very close to my window.  Those sleepless nights worrying about whether there are monsters in the bed have been made worse by constant worrying day and night about whether monsters will climb the tower and break in through the skylight.  To allay the panic, I make sure that I have closed all the windows before leaving (because, obviously, locked windows are like force-fields that will keep you safe).  Of course I don't really factor in that it's been a heatwave here recently, and I'm on the top floor, so it will be hot and sticky when I return, which makes it more likely for me to itch and think I'm being attacked by a wasp...

So what can you do?  Force yourself to remember that for over ten thousand sleeps you've only ever been awoken by a wasp once?  Take a deep breath, count to ten and decide that this time it is ok to go out with the window locked open instead of locked closed?  Take to the internet and inflict a thousand words of frustration on whichever kind souls are still reading this?  Or perhaps accept that things will rattle you sometimes, and you know what, that's ok.  Rituals fade and change over time, and as long as you can see them come and go without obsessing too much about them, then you'll be fine.  At least, that's what I tell myself.  Now if you'll excuse me, I need to roll up my jeans as it feels like something is crawling up my leg...

Monday, 12 August 2013

Challenges

Carcassone.  I play a lot of this at the moment.
This particular game has gained a wayward pig.
Games, competitions, challenges and races.  There are many reasons to take part in such activities, but "to win" (to outperform the other entrants) really isn't a good one.  That's not to say that winning an event is without its upsides -- I still smile when walking past a framed certificate at work that heralds a win at a team challenge day in 2004, the prize that day was my first IBM laptop -- but what happens when taking part, the people you meet, the experience you gain and the stories you can and will tell again and again are much more crucial.  Sure, I'll try my hardest to win at a friendly game of Carcassone, but I'll also enjoy the opportunity to catch up with my friends, and have a laugh at each of our fortunes with the little cardboard tiles.

Some challenges are bigger than others.  A game of Carcassone can last up to a few hours (sometimes as long as "gone midnight"), but recently I've found myself involved in a couple of much larger events, and having a lot of fun with them.

This artist's impression of sunrise over Jack & Jill,
as this artist's camera phone is rubbish in low light!
First up was the Oxfam TrailWalker a few weeks ago.  A friend decided to form a team ("Gimme Shelter"), and look for team-mates.  The idea of walking 100km in 30 hours really didn't appeal to me, but being part of the support crew sounded like a lot of fun.  Staying up all night, reading driving instructions to our driver, making hot chocolate and finding the one tube of Deep Heat lost down the back seat of the car for the walkers - count me in!

Here the point was absolutely not to win, it was a team effort and every checkpoint reached was an impressive feat.  Having said that, the the team did amazingly well (they completed it!).  Acting as support was of course a lot less challenging than walking  but I still got a lot out of the overnight experience.  If nothing else, it is very rare that I get to watch the sun set, stay up all night talking and drawing and pouring drinks, and then see the sun rise again.  I even got to have a nap on a sunny morning on the south downs.


Early morning at Jack & Jill

Mini jelly-babies make good, if not somewhat
temporary morale boosting team mates!
The second event is one that has become a bit of a ritual for me.  Days get booked off work for it, and preparatory shopping takes place to ensure I have enough pot noodles, breakfast bars, and Haribo to sustain me for 72 hours.  It is, of course, a programming competition.  The Programming Contest of The International Conference On Functional Programming.

The challenge problems set are always deeply interesting (this year's can be found at http://icfpc2013.cloudapp.net/), and I find it really refreshing to fully engross myself in a problem for a fixed set of time, knowing that (for those days at least) the rest of the world can be on hold.

What's even better though is that at the end of the competition, I have something I can look back on.  My friends and I still discuss previous competitions, what we did, what we could have done differently, laughing about the horrible hacks and stupid tools we wrote in a frenzy to help increase our score.  We do try to do well (and usually don't completely embarrass ourselves), but we know we'll never win, and that's OK.  The clich├ęd taking part isn't what counts, but that you come away knowing more about yourself, with more experience to draw on, fun memories to keep, and hopefully interesting stories to tell.

One of my ICFP Competition traditions is to make some overblown complicated visualiser for the task.
Usually using some gratuitous and highly dubious technology choices.  This was the year of websockets!

Saturday, 27 July 2013

Hayle Beach and Tate St Ives



Summer, and a heatwave has hit the UK.  Taking full advantage I took a short holiday in Hayle, Cornwall, which has a glorious beach.  Five days of listening to the tide come and go, watching the sun set, and leaving only footprints in the sand is a great way to escape from the noise of London and just switch off and reset.  Then, by night, I had Haven's entertainment offerings to provide hours of quizzes, Spice Girl tributes, drinks and silly dancing.  What more could you possibly want?    
Moss, White, Red and Black 1949
(not at the Tate, but an illustrative example)
http://onmondrian.blogspot.co.uk/2013/06/more-marlow-moss.html
Where I was staying was a few minutes away from St Ives by train, and I spent a day there looking around. Particularly interesting was the Tate gallery, especially an exhibition of the works of Marlow Moss.

Her works were varied and striking.  She had links to Mondrian (rumours abound that she influenced him with parallel black lines), and several of her abstract canvases of white, with black lines and red, yellow or blue colour squares were on display.  A particular favourite was her Composition in Red, Black and White - (if I could find a print of it I'd buy it, but no such luck).  Having never really paid much real attention to art, Neo-plasticism and Mondrian like works were only really on my radar from a particularly good episode of Hustle, however I am now starting to see the appeal.

But you could see her work evolve.  Later the black lines were replaced with raised solid white blocks, and the colour rectangles were painted in the wells.  Black was replaced with shadow, to create a different set of effects.  And then even later the abstract blocks and colour were gone, replaced by everyday objects (like strings or rope) stuck to a white canvas and painted white to match.  Akin to my paper city from a while ago, the interest was in the change of shade and tone.  Other works more physical works of sculpture also provided distraction, mechanical constructions that look like they were designed to rotate but are in-fact fixed, and granite and gunmetal juxtapositions.

Afterwards the cafe there also did some very nice Smoked Salmon sandwiches, before returning to the beach.