# Latest Posts

This week I stumbled upon someone wondering whether the **second part** of the recent Advent of Code puzzle “Seven Segment Search” can be expressed as a constraint satisfaction problem.
As attested by the replies: yes, it can.
However, I think the question deserves a more extensive discussion than just a few comments in a thread.
This post tries to provide a more instructive answer and raise awareness for the tradeoffs or solver misuses some solutions put up with.

I assume that the reader is familiar with mathematical notation and

- just struggles to express the posed problem in a formal, declarative way,
*or*
- is interested in seeing how the SMT solver Z3 can be used to express and solve the problem in several logics.
It takes only few steps to get from a quantifier-laden high-level formulation to what is effectively propositional logic.

» Read more
Recently I got interested in designing personalised crosswords as a way to spice up photo book presents.
This made me realise how hard generating high-quality

crosswords actually is.
Trying to create a crossword from a set of words – or a subset thereof – I checked out several tools but found all of them to be based on heuristics and yield rather sparse crosswords.

In line with the general theme of my previous posts, this one illustrates how we can leverage SAT solving to solve this problem.
In contrast to related approaches, which assume a fixed grid structure and search for fitting words, we consider word placement as part of the problem and eventually end up with an integrated solution to generating crosswords of adjustable quality.

» Read more
Back in the day, Mastermind was a popular two player code-breaking game, and many variations thereof still exist as both standalone games and puzzles within other games.
Although it is difficult for a human player to make *optimal guesses* of the secret code, or at least guesses that do not conflict with the provided clues, the setting is usually simple enough for an AI to find such candidates via explicit exploration of the game tree.

However, such approaches become unfeasible when the number of possibilities for secret codes grows into the millions.
This post illustrates the problem with standard approaches, and how finding consistent candidates can be approached with SAT solving – yielding an AI that can handle orders-of-magnitude harder Mastermind instances.

» Read more
A few weeks ago, I was asked the following riddle:
Design a logic circuit with three inputs and three outputs, such that the outputs are the inverted inputs. You may use arbitrary many AND and OR gates, but at most two NOT gates

.
Although the characterisation of this problem as an SMT instance is straightforward, I found it necessary to reduce it to SAT and incorporate further assumptions to achieve reasonable performance.

This post illustrates said process, ranging from the original idea to a standard formulation of SAT-based logic synthesis to a problem-specific and more constrained instance.

» Read more
While there is a mathematical explanation for the choice of `0x5F3759DF`

in the famous bit-level hack for approximating the multiplicative inverse of the square root of a 32-bit floating-point number, it is not immediately clear to what extent the reasoning is really applicable in the context of machine data types and their peculiarities.
This post illustrates how this, and related aspects, can be investigated with SMT-based reasoning about the actual implementation.

» Read more