home
about
logo
blog
contact
portfolio music conlangs video games board games puzzles square dancing

Penalty theory in dynasty puzzles

2022-07-27 04:44 -0400 puzzleslogic puzzlesmath

Nikoli-style pencil-and-paper logic puzzles, like Sudoku, Yajilin, and many more, have very simple rules. But you can often build puzzles that require thinking in really cool ways, seemingly totally unrelated to what the rules literally say.

One example is commonly called penalty theory, which has been written about before in e.g. this Twitter thread by agnomy (Japanese), this blog post by chaotic_iak (English), or this blog post by redstonerodent (English). However, the way penalty theory is usually explained still seems to leave some people confused.

So here's a different description of penalty theory, which I personally find to be the most intuitive.

Note: This post is long! But don't worry: lots of space is taken up by pictures, and you only need to read about half of the post to understand basic penalty theory.

dynasty puzzles

The standard "penalty theory" applies to puzzles with these rules:

Puzzle types which include all of these rules are sometimes called dynasty puzzles.

There are many kinds of dynasty puzzles, but the one most conducive to penalty deductions is Heyawake. In Heyawake, in addition to the rules above, there are also "rooms" with numbers in them, which are required to contain that many shaded cells.

You can click the first image to try the puzzle, or click the second image to see the solution.

223321111 223321111

Heyawake also has one more rule, which we won't worry about for the purposes of this post. (But if you want to solve other Heyawake puzzles, make sure you learn the full rules!)

use-case

Penalty theory is about how to fit as many shaded cells as you can into a given space.

You may notice that both of the dynasty rules are restrictions on how the shaded cells can be placed. So penalty theory can only apply when there is some other constraint, like the rooms in Heyawake, that forces you to shade a large number of cells.

Here's an example. Like all logic puzzles, there's only one possible solution, so you probably can't solve it by guessing. But once you've learned penalty theory, it will suddenly go from basically impossible to fairly easy!

2903

(This puzzle was created by @agnomy on Twitter.)

counting pools

To talk about penalty theory, I'm going to introduce the concept of a pool.

Consider all of the gridpoints in the grid. These are all the places the grid lines intersect.

123456789101112

You can think of shaded cells as connecting all the gridpoints they touch together. In the example below, the starred gridpoints are connected.

Also, some shaded cells connect gridpoints to the edge of the grid, like the triangular gridpoints in the example below.

A "pool" is just a group of connected gridpoints which does not connect to the edge. In the example below, there are 8 pools, all marked with their own shape.

To continue the metaphor, you could think of the edge of the grid and everything connected to it as "the ocean".

It's easy to count the number of pools when there are no shaded cells: just multiply (width−1) by (height−1). For example, this puzzle is 8 cells wide and 4 cells tall, so it starts with 7 × 3 = 21 pools.

123456723

consuming pools

The reason we care about these pools is that shading a cell changes the number of pools in a completely predictable way.

In particular, when you shade a cell, the pools corresponding to its four corners are combined to become a single pool. Some of them might be the ocean, like if you shade a corner:

Or an edge:

Or they might all be different:

In the corner example, whichever pool the starred gridpoint belongs to becomes part of the ocean. So the number of pools decreases by 1.

In the edge example, both the star and triangle pools become connected to the ocean. So the number of pools decreases by 2.

In the interior example, the four pools on each of the four corners are all joined into a single pool. So the number of pools decreases by 3.

You might be suspicious that I'm assuming different symbols belong to different pools – and rightfully so! But remember that the dynasty rules say that the unshaded cells must form a single connected group. If any of the different symbols drawn were actually the same, then you could draw a line of shaded cells through whatever connected them. This would "rope off" an area of unshaded cells, disconnecting it from the rest of the puzzle.

To summarize,

But there's another way of thinking about this, which I personally like more.

(There's actually a good reason this works: every edge of a shaded cell touching the border of the puzzle corresponds to allowing two of the pools it joins to be the same.)

I'll give explanations with both styles of counting; you can use whichever one you like better.

but how do I actually solve a puzzle?

From all that, we get a nice formula:

remaining pools = (width−1)×(height−1) − (# corners) − 2×(# edges) − 3×(# interior)

or, with the other counting method,

remaining pools = (width−1)×(height−1) − 3×(# shaded)
  + # shaded on top edge
  + # shaded on bottom edge
  + # shaded on left edge
  + # shaded on right edge

At first, this might not seem very useful for solving puzzles, because you don't know how many corner and edge cells you're going to end up shading. But remember that penalty theory applies to puzzles where you're trying to shade as many cells as possible.

You have a limited supply of pools. So since corners and edges consume fewer pools, you had better shade as many of them as possible to avoid running out of pools.

This is confusing without an example. I'll demonstrate the technique on this puzzle (created by me).

192222

(Click the image to open the puzzle in a new tab if you want to try it yourself or follow along.)

How do I start? Well, here are all the facts I know:

So there are 63 pools available, and shading 27 cells on this grid costs at least 63 pools! That means I must shade as many corners and edges as possible, and there will be no pools left over (in other words, every gridpoint will be part of the ocean).

Great! Concretely, I can now start by shading all the corners.

192222

I need to shade 2 cells in the top right room, and then some more cells will be unshaded because of the dynasty rules.

192222

Now there's only one way to fit enough shaded cells on the top and right edges.

192222

Both the star and the triangle have to connect to the ocean somehow. But I can only shade one more cell in the 2 room. So it has to be the middle one, so that both the star and the triangle can escape.

192222

Now there are some nearly-trapped pools, marked above, which only have one way to escape. Also, shading the corresponding cell will create another nearly-trapped pool next to it, resulting in a chain of similar deductions.

192222

The remaining 2 rooms both already have one shaded cell in them, and to fit enough shaded cells on the edges, one of them has to go in each of the 2 rooms. So I can mark all the non-edge cells in the 2 rooms as unshaded.

192222

Again, there are a bunch of marked pools that only have one escape route, and again they will lead to more of the same:

192222

192222

Solved!

optional: deeper down the rabbit pool

So that's how to apply penalty theory to the whole puzzle. But what if you only want to use it on a certain part?

143101

This puzzle has a big number in it, but if you try to apply penalty theory to the whole thing, you'll find that there's a lot of wiggle room. Is it possible to use penalty theory on just the big number?

It turns out it is! Consider just the 14 room, and pretend the rest of the puzzle doesn't exist.

1431011234567891011121314151617181920212223242526272829303132333435

Let's count:

Nice! Again, I need as many corners and edges as possible, and all pools must connect to the ocean.

Some pools (namely 24, 32, 34, and 35) are already almost trapped, so I'll start by placing the shaded cells that let them escape.

14310112171722171727272727

Now some more pools (marked on the grid) are almost trapped, and I can also fill in the left edge.

143101

The rest is straightforward.

Now it's time to look at the 10. Notice that some of its gridpoints are already part of the ocean.

14310112345678910111213141516171819202122232425

Counting again:

Hmm, there's one extra pool left over. That could mean one of two things: either I won't be able to shade as many corners and edges as I thought, or there'll be a pool that doesn't connect to the ocean.

In this case, the answer is a little tricky. Because of the 3 room, there will be another shaded cell touching the top of the 10 room. This shaded cell will touch either pools 1 and 2 or pools 2 and 3.

Hypothetically, let's say it touches 2 and 3. Then, pools 2 and 3 will be connected from the outside. But remember, I'm only looking at this subregion of the puzzle, and I'm pretending the rest of the puzzle doesn't exist. So from the perspective of the penalty computation, 2 and 3 aren't actually connected yet, and connecting them from inside the subregion would be illegal! (That would create a closed-off area of unshaded cells, for the same reason as described in the counting pools section.)

Therefore, pools 2 and 3 will remain separate pools within this region. And since I know there's only room for one pool left over, that means everything else has to connect to either 2 or 3, one of which will end up connecting to the ocean.

Now all the pools are accounted for, so I know that all pools must connect to the ocean or the remaining pool, and corners and edges are maximal.

143101

The next step is a bit tricky, and you might find it easiest to just proceed by trial and error. But here's one reasonable argument: all of the starred gridpoints have to touch a shaded cell within the 10 room (either to fit enough edges or to let pools escape), which accounts for all 6 remaining shaded cells in the 10 room. So the 7th cell in the 5th row must be unshaded.

143101

Now the cell marked in gray must be shaded to avoid trapping too many pools, and you should be able to solve the puzzle from there!

143101

As promised, the original pool 2 does not connect to the ocean through the 10 region, showing where the inefficiency of 1 pool comes from.

appendix: an alternative counting method

If you're happy with the strategies described, you can skip this section. But there's a further simplification that can help speed up the counting, at the cost of requiring a little more math.

Consider the second formula from before.

remaining pools = (width−1)×(height−1) − 3×(# shaded)
  + # shaded on top edge
  + # shaded on bottom edge
  + # shaded on left edge
  + # shaded on right edge

If we're applying penalty theory to the whole puzzle, we can establish a better baseline. Usually, we're shading as many edge cells as possible, so it makes more sense to count the deficit of shaded edge cells.

remaining pools = (width−1)×(height−1) − 3×(# shaded)
  + max # shaded on top edge# missing on top edge
  + max # shaded on bottom edge# missing on bottom edge
  + max # shaded on left edge# missing on left edge
  + max # shaded on right edge# missing on right edge

What's the maximum number of cells we can shade on an edge? Consider the top and bottom edges together. If width is even, we can shade width÷2 cells on both the top and bottom, for a total of width combined. If width is odd, we can shade (width+1)÷2 cells on both the top and bottom, for a total of width+1 combined. So we get:

remaining pools = (width−1)×(height−1) − 3×(# shaded)
  + width + 1 if width is odd
  + height + 1 if height is odd
  − # missing on each edge

Doing some simplification and moving things around so that everything is positive, we end up with:

width×height + 1 + 1 if width is odd + 1 if height is odd
  = 3×(# shaded) + remaining pools + # missing on each edge

The left-hand side of this equation doesn't depend on the shaded cells at all! So you can compute it immediately upon seeing the puzzle. If you think of this as how many penalties you have available, then:

As a quick demonstration, for the example puzzle from the previous section, the left-hand quantity is 10×8 + 1 = 81, and just placing all the shaded cells costs 27×3 = 81 penalties. So this is another way of seeing that all pools must connect to the ocean, and that the edges must hold as many shaded cells as possible.

For the mathematically inclined, we can produce a similar formula for arbitrary rectangles:

penalties = (width−1)×(height−1) + Σb ⌈b/2⌉

where the sum is over lengths of edges touching the border. For shapes more complicated than rectangles, I think it's easiest to use the other method.

appendix: an etymological edification

So anyway, why are these things called "pools"?

The original description of penalty theory used the graph of unshaded cells instead of gridpoints. This is just the thing you get if you draw a line between every touching pair of unshaded cells.

Then, instead of pools, it talked about "fundamental loops". There are five of them in this example.

A loop is a path you can draw along these lines that starts and ends at the same place.

But why doesn't this one count?

That's what "fundamental" means: the red loop is just a combination of the pink loop and the green loop. More explicitly, the number of fundamental loops is the biggest number of loops you can choose so that none of them are combinations of any others. (There can be many ways to do this; for example, you could take the pink loop and the red loop, but then you couldn't count the green loop.) There are also a few extra considerations when applying penalty theory to only part of the puzzle. This all feels more confusing to me, which is why my presentation uses pools instead.

But if you like loops more, you can almost just replace the word "pool" with "loop" on this page and keep basically everything else intact. In fact, pools and loops are almost "the same thing" – in mathematical jargon, pools are the dual of a particular basis of loops. That's why I chose the name "pool": it's "loop" backwards.

appendix: patterns, pitfalls, and practice

Here are a few more examples of various levels of trickiness. Many of them are easy to solve without penalty theory – the point is to make sure you understand how the penalty calculations work. You can try working through them yourself first, for practice.

For all of these,

puzzle 1

05 05

Region to apply penalty to: the 5 room

Computation: 16 pools available, costs at least 3×5 = 15 pools

Explanation: This might trip you up at first. It seems like the solution is maximally efficient, but shouldn't we have 16 − 15 = 1 extra pool? In fact, this region doesn't connect to the ocean at all, so there is indeed necessarily at least 1 pool left over.

puzzle 2

71211 71211

Region to apply penalty to: the whole puzzle

Computation: 25 pools available, costs at least 3×12 − 3 − 3 − 3 − 2 = 25 pools

Explanation: If you deduce that two edges next to each other both have the maximum number of shaded cells that can fit, you can safely shade the corner between them. But in this example, the right edge is inefficient – you should be careful to not falsely apply this "deduction" in this case.

comments

There are no comments yet.

formatting is supported. comments require manual approval.