ciphergoth: (Default)
Paul Crowley ([personal profile] ciphergoth) wrote2006-12-28 03:52 pm

Puzzleicious

I had a lovely Christmas with [livejournal.com profile] spikeylady, [livejournal.com profile] some_fox, [livejournal.com profile] buttonmeup, [livejournal.com profile] yerbury and family.

I got given a "Tantrix" puzzle for Christmas as a stocking present. It contains 10 hexagonal tiles; you have to lay the tiles out to create a loop of one colour such that all the edges match up.

Actually solving the puzzles quickly lost my interest, so instead I wrote a program to solve them. Then I got interested in making a nice display of the results. I've now found all 2706 solutions to the 12 puzzles that form part of the set.



For those interested, the solver is in Python, and uses Cairo for drawing.

[identity profile] marnanel.livejournal.com 2006-12-28 04:07 pm (UTC)(link)
you should send that to [livejournal.com profile] jwz for xscreensaver.

[identity profile] ciphergoth.livejournal.com 2006-12-28 04:48 pm (UTC)(link)
Hmm, not sure

- I don't think he'd want to bring in either Python or Cairo as dependencies
- if it becomes part of a package like xscreensaver the puzzle makers might mind on copyright grounds
- it's not all that animated

but thanks - I'm glad it looks the part :-)

[identity profile] fuschiafaery.livejournal.com 2006-12-28 04:13 pm (UTC)(link)
Sounds like a very techie way of puzzle solving, I think you got a tad further than most of us would have done :-)

[identity profile] ciphergoth.livejournal.com 2006-12-28 04:21 pm (UTC)(link)
I realized in the end that I quickly get bored of trying to solve these things by hand, but I enjoy writing programs to solve things!

[identity profile] wechsler.livejournal.com 2006-12-28 05:29 pm (UTC)(link)
ISTR [livejournal.com profile] darkpoint got bored of Sudoku and also wrote a solver instead.
djm4: (Default)

[personal profile] djm4 2006-12-28 07:48 pm (UTC)(link)
Yes, so did my sister.

[identity profile] drdoug.livejournal.com 2007-01-02 04:12 pm (UTC)(link)
And me!

[identity profile] ciphergoth.livejournal.com 2006-12-29 08:24 am (UTC)(link)
Funnily enough, I got another puzzle for which I started on a Prolog solver having had great success using it to solve a similar puzzle many years ago, but [livejournal.com profile] some_fox solved the puzzle by hand before I was barely started, and it sort of took the wind out of my sails...

[identity profile] valkyriekaren.livejournal.com 2006-12-28 04:15 pm (UTC)(link)
Heh. Must have been the season for it - [livejournal.com profile] d_floorlandmine got a Tantrix too.
zz: (Default)

[personal profile] zz 2006-12-28 07:05 pm (UTC)(link)
i wish i were a creative enough programmer to know how to think about such things in computer-solvable terms. :|

[identity profile] ciphergoth.livejournal.com 2006-12-28 07:40 pm (UTC)(link)
It's not a very creative solver - pick a tile, then pick a tile (and orientation) to go next, check that all the edges match properly and there's no tile already there where you want to place one, carry on until you close the loop or you don't have enough tiles left to get back to the start, then backtrack. The solution space is sufficently small for this to work, though you have to leave it overnight to get all the solutions.

[identity profile] vulture23.livejournal.com 2006-12-28 07:19 pm (UTC)(link)
Of course, my first thought was "Ooh, I'd like to see the code for that..." :)

[identity profile] vulture23.livejournal.com 2006-12-28 07:49 pm (UTC)(link)
Thanks!
henry_the_cow: (Default)

[personal profile] henry_the_cow 2006-12-28 11:23 pm (UTC)(link)
Is the body of __sub__ supposed to contain + signs? If not, I presume this doesn't affect the result, on the "it seems to work" principle.

We got one of these puzzles last year and I had great fun solving it, by hand. Maybe I should learn Python (not that I have any time to code these days).


[identity profile] ciphergoth.livejournal.com 2006-12-29 02:22 am (UTC)(link)
eek!

It's likely that it hasn't found all the possible solutions then, since that bug will break the distance-based cutoff critereon.

Thanks for spotting it!
henry_the_cow: (Default)

[personal profile] henry_the_cow 2006-12-29 10:17 pm (UTC)(link)
You know, this notion of open-source review just *might* catch on...

[identity profile] ciphergoth.livejournal.com 2006-12-30 10:51 am (UTC)(link)
fixed version (with many other things fixed too - eg transformations make the drawing code much simpler). Let me know if you spot anything else - thanks!

[identity profile] ciphergoth.livejournal.com 2006-12-29 11:47 am (UTC)(link)
It turns out that the distance-based cutoff was completely broken anyway, so all solutions were found. However, fixing it has made the solver faster. I have also replaced functional composition with matrix composition for composing transforms, which is also faster.

[identity profile] bileandvitriol.livejournal.com 2006-12-28 07:51 pm (UTC)(link)
Did you ever do that puzzle that Matt Selby's brother Alex solved?

[identity profile] ciphergoth.livejournal.com 2006-12-28 10:02 pm (UTC)(link)
I only recently found out about that - neat or what?
barakta: (Default)

[personal profile] barakta 2006-12-28 10:09 pm (UTC)(link)
My dad got into Googlewhacking and our response was 'why don't you code up a solver' as he did used to be a programmer. Scarily he seems to enjoy the process of manually solving them, almost iterating the program himself. He's had Tantrixes and other computer solvable games as presents for years and plays with them for weeks noting his results on backs of envelopes before getting bored of them. They do sudoku as well.

Then again this is a man who deliberately signs up (or at least doesn't avoid it) for spam, sets it to come in to an old email address in Outlook Express and then sorts it manually by hand and gets all fascinated by the categories.

[identity profile] purplerabbits.livejournal.com 2006-12-29 11:22 am (UTC)(link)
You know, the moment I saw that puzzle in one of Jess's pictures I *knew* you'd do that!

Tantrix

[identity profile] thekumquat.livejournal.com 2006-12-30 09:30 pm (UTC)(link)
Tchah - they had that in the castle we were in this week and I'd got all of them up to 9, but not the 10 one!

Just a minute - your pic there doesn't have a 4th colour which appears on the last 3 tiles - are you sure you've replicated the puzzle accurately?

Re: Tantrix

[identity profile] ciphergoth.livejournal.com 2006-12-31 12:57 am (UTC)(link)
yes, my puzzle only has three colours on all the tiles. I've constructed the answers with the real tiles so I'm pretty sure I have them right - down to which colours occlude which on each tile :-)

But I could extend it to do the other puzzles... :-)

[identity profile] drdoug.livejournal.com 2007-01-02 04:14 pm (UTC)(link)
I like your brains.

[identity profile] ciphergoth.livejournal.com 2007-01-12 05:56 pm (UTC)(link)
Thanks :-) Spicy or non-spicy?

[identity profile] drdoug.livejournal.com 2007-01-12 09:38 pm (UTC)(link)
Spicy brains smell best!