Tech News
← Back to articles

Solving a wooden puzzle using Haskell

read original related products more articles

April 28, 2025

This post is the first of a two-part series that describes my computer-assisted solution to a physical puzzle I got. In this first part, I describe the problem and model it in Haskell. This post is a little verbose, so feel free to skip directly to part II, where we'll see how to tell our computer to actually solve the puzzle.

I got gifted a puzzle recently, allegedly a "very hard one". After receiving it, I spent a couple minutes trying to solve it, but it quickly became clear that, unless there was a trick I'd missed, I didn't have the right combination of patience and brainpower for that. I had some family and friends try to solve it too, and although some of them displayed an impressive amount of persistence, none was persistent enough to crack the puzzle either.

You know who else is incredibly persistent? My computer. It's not nearly as smart as the humans around me and I, but it makes up for that in speed and tirelessness. So if I manage to tell it exactly what to do, it might be able to find a solution. Let's try!

The source for this post and the next is a literate Haskell file. This means you can run the code by running cabal run wooden_puzzle.lhs . You can also experiment with the values defined in it by running cabal repl wooden_puzzle.lhs .

The following pieces of code are here to tell the Haskell toolchain how exactly to interpret the file, and what our dependencies and imports are. I'll also update them based on what I import in the second post.

{- cabal: build-depends: base ^>= 4.17, linear ^>= 1.23, time ^>= 1.14 default-language: Haskell2010 build-tool-depends: markdown-unlit:markdown-unlit ghc-options: -pgmL markdown-unlit -Wall -}

module Main where import Data.Time.Clock ( getCurrentTime , diffUTCTime ) import Linear.Matrix ( M33 , identity , transpose , det33 , (!*!) , (!*) ) import Linear.V3 ( V3 (V3))

The Puzzle

Here's what the puzzle looks like:

... continue reading