Start Free Trial

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
DavidP
17 - Castor
17 - Castor

This article is part of the Alteryx Obscura Blog series. Alteryx Obscura is the Inspire session dedicated to all things non-analytics, highlighting what the software “can” do rather than what it’s “supposed” to do. 

 

image001.png

 

Continuing on the Obscura blog series, the puzzle solver was my Obscura submission for Inspire 2024 - my first time on the Obscura stage! It will probably always be my favorite one, and I think it would be very hard for me to come up with anything to beat it. I just think it’s soooooo cool, even if I have to say so myself!

 

It was inspired by YouTuber Shane Wighton and his channel Stuff Made Here.

 

I was watching this specific episode with my kids where he solved a 4000-piece (pictureless) white puzzle on a gigantic flatbed with a robotic pick and place arm that he designed and built, and of course, the software to solve the puzzle and put the pieces in the right position.

 

So I thought, how about trying this in Alteryx? I picked an equally complex puzzle to solve – 81 pieces! Mainly because it was the best image I came across when I started looking for a picture of a white puzzle to solve.

 

image003.png

 

Building the Puzzle Solver

 

If you haven’t guessed it already, the plan was to solve this as a spatial problem. In order to do that, I had to turn my JPG into an SVG (Scalable Vector Graphics) file. From that, I could then convert it to coordinates - 69,232 to be exact.

 

Of course, I wanted to see what it looked like in Alteryx, so I decided to plot it as a polygon…

 

image005.png

 

At this point, it dawned on me that there might be a tiny sequencing issue, but not to worry - that’s a problem for future Dave! What I actually needed was 81 individual polygons for each of the pieces, so that was the problem I concerned myself with next.

 

An 81-piece puzzle is a 9x9 grid, and since I could figure out the XY min and max for the entire puzzle, I could work out the centre point for each piece with reasonable accuracy. I could then create a buffer area around each of the centres and make it big enough to capture all the points for every piece. Sure, it would also contain some points that don’t belong, but I just need to figure out which ones they are and get rid of them.

 

image007.png

 

I still had the sequencing issue, though, but as I said - future Dave’s problem.

 

image009.png

 

Just like in the YouTube video, getting to a place where I had clean individual pieces quickly became the main object of the exercise and no longer future Dave’s problem. The future was now, so to speak, if that was even possible in either a physical or grammatical sense.

 

After some deliberation with myself, I decided on a shortest path algorithm approach to both determine the right sequence of the points and to discard any unwanted points. This approach did eventually work. Kinda. Mostly. Ok, let’s just agree that I wrote a flawless algorithm, implemented with an iterative macro, that worked perfectly for all the pieces and move on. Ok?

 

I decided to make each piece a tiny bit smaller, just so that I could distinguish them from each other when they’re plotted together.

 

image011.png

 

And the full monty looked like this.

 

image013.png

 

So after roughly 2 months of messing around with points and polygons, iterative macros and algorithms that I didn’t really understand, I finally had a puzzle to solve!!

 

So now what?

 

Solving puzzles is all about the edges! If you can break every piece up into its 4 edges, you can take a single edge of a single piece, overlay all the edges from all the other pieces onto that edge, and find the perfect match!

 

I did make the problem a little bit (ok, a lot) easier for myself by not rotating any of the pieces. If I’m trying to match a right edge, I only have to test the left edges of all the pieces, and so forth.

 

Each piece had a unique ID. But a piece now consisted of several things:

 

  1. The original set of points
  2. The piece is drawn as a polygon
  3. 4 polylines that represent the 4 sides
  4. The points for each side

 

I called this - the compound piece!

 

One thing that made me sad was that you can’t move polygons or polylines in Alteryx. You have to deconstruct them into points, move the points by the required offset distance, and reconstruct them. I guess the spatial tools were not really designed for puzzle building or any kind of puzzle work.

 

Deciding which points belonged to which edge and therefore splitting each piece into 4 edges did have a fair amount of trickiness about it, until I decided to, well, cheat. I plotted the full puzzle of 81 polygons in its solved state and then created a small buffer around each piece. That meant that the buffers of adjoining sides created a nice intersection that contained the 2 edges in question, which I could extract with a spatial process.

 

So now that I had each piece defined by its individual edges, I could place a starting piece somewhere and find all the pieces around it, as shown below. I can then make one of the other pieces, the current piece, repeat the process, and so on. Once a piece is used, I remove it from the unmatched pile so that it doesn’t just match the same pieces over and over and get on with the solving business.

 

image015.png

 

It felt like I finally cracked Alteryx puzzle-solving. But the thing kept getting stuck. It seems that I have taught my puzzle-solving workflow to paint itself into a corner, time and time again.

 

So now I had to be a lot stricter with it. I picked the left bottom piece as my starting piece and only allowed it to solve column by column, from left to right, which finally brought success.

 

Takeaways

 

As I said before, this might just be the coolest thing I’ve ever done in Alteryx. It really was months and months of work for 4.5 minutes of airtime. And that’s the spirit of Obscura. We do it for the love of learning, the love of doing something ridiculous, etc. No minute/hour/day/week of learning is ever time wasted.

 

Until now, I’ve never had the chance to explain to anyone how the whole thing came about and then developed. When I first got the idea, I wasn’t very confident that I would actually be able to do it. But I stuck with it and kept solving one step at a time. Sharing the whole process brings back great memories.

Comments