Recursion and Abstraction
Look Past The Numbers
Recursion
Take a look at the following 2 half-lanes:
| 3 | 5 | 6 | |||||
| 2 | 6 | ||||||
In , we only have left to work with. None of these are taller than or , so we know those 2 will be peaks.
This means before the , there must be 1 more peak (so that we have 3 in total). The only way for that to happen, is for the skyscraper in the head cell to obscure that in the 2nd cell:
| 3 | 234 | 123 | 5 | 6 | |||
| 2 | 6 | ||||||
Now look at . We know there’s 1 more peak before the lane peak . Again, the only way for this to happen is if the head cell obscures the 2nd cell:
| 3 | 234 | 123 | 5 | 6 | |||
| 2 | 2345 | 1234 | 6 | ||||
Now, I want you to look past the numbers. What kind of structure did we deduce here?
The skyscraper in the 1st cell obscures that in the 2nd cell. So we’ve got a “high” followed by a “low”. Let’s replace our pencilmarks with just those indicators:
| 3 | high | low | 5 | 6 | |||
| 2 | high | low | 6 | ||||
Aha! Now you can very apparently tell, fundamentally these are the same problem. The numbers may be a little different, but the underlying constraint is the same in both lanes.
Why exactly is that? Well, we’ve guaranteed 2/3 of the peaks the -clue half-lane needs, so we need exactly 1 more peak. And we’ve guaranteed 1/2 of the skyscrapers the -clue half-lane needs, so we… also need exactly 1 more peak.
Solving a 2/3 half-lane is the same as solving a 1/2 half-lane. Or a 4/5 half-lane. Or a 6/7 half-lane.1 Or a 69/70 half-lane. In all these cases we only need 1 more visible skyscraper before the current first peak, so they’ve all been reduced into solving a -clue half-lane.
We can illustrate this even clearer with a higher clue:
| 4 | 6 |
With only the lane peak solved, we still need 3 more skyscrapers visible. This ‘feels like’ solving a -clue.
Suppose we find another peak:
| 4 | 5 | 6 |
Now we have 2 skyscrapers guaranteed to be visible, so we need 2 more. Notice this ‘feels like’ solving a -clue!
| 4 | 5 | 6 | |||||
| 3 | 6 |
In both half-lanes, we need 2 more peaks.
And as we find another peak, meaning we only need 1 more, it now ‘feels like’ solving a -clue.
| 4 | 4 | 5 | 6 | ||||
| 2 | 6 |
In both half-lanes, we need 1 more peak.
So as we find more peaks, the problem reduces into a smaller version of itself. We’re solving recursively.
The recursion happens because we don’t care what comes after the first current peak. These peaks can’t change:
| 4 | 4 | 5 | 6 |
The and are gonna be visible no matter where we go from here.
So, we can ‘mentally ignore’ those later skyscrapers, and treat the current first peak as the lane peak! Then we just have to decrease the clue accordingly:
| 2 | N | - | - |
Of course, it’s not actually the -skyscraper, but we can think of it as the lane peak.
Now we have a much simpler problem on our hands.
[!Note] I’m not saying you need to write this out explicitly – I personally visualise this process in my head. But actually, you totally could write it out! Then you’re just keeping track of “how many more skyscrapers do I need visible”?2
The important part is, we can leverage all the deductions we already know that apply to -clues. This isn’t a literal -clue, but it’s effectively a -clue.
For instance, in this particular case we know must go in the head cell (via Blockade):
| 2 | 3 | 4 | 5 | 6 |
There’s a good chance you already knew this intuitively, but now you can see why it works. You’re not applying a special-case deduction for -clues with 3 solved peaks; you’re using the simple rules you already know in an originally complex situation that has been simplified.3
Abstraction
Recursion also illuminates a closely entangled idea: when solving Skyscrapers, it’s not the numbers that are important, it’s the structure.
The numbers are just symbols for an underlying logical structure. Looking back at the and we had earlier, it’d be no different if we had a 99x99 Skyscrapers:
| 3 | high | low | 98 | … | 99 | |||
| 2 | high | low | 99 | … |
Regardless of what the concrete numbers may be, the abstract structure remains the same. It’s that structure which we work with, reason about, and perform logical deductions on.
We might as well use emojis for our skyscrapers! – though that would make puzzle-solving pretty painful.
In fact, who said our skyscrapers even needed to have consecutive heights? We could have a 6x6 Skyscrapers with the digits . It’s irrelevant, really, the only necessity is that they’re unique so that the rules of Sudoku can be applied.
| 2 | 2 | 3 | |||||
| 6 | 9 | 3 | 7 | 1 | 0 | ||
| 1 | 3 | 0 | 6 | 7 | 9 | ||
| 2 | 5 | 7 | 1 | 0 | 6 | 3 | |
| 2 | 6 | 9 | 3 | 0 | 1 | ||
| 3 | 0 | 7 | 1 | 9 | 6 | ||
| 4 | 1 | 6 | 9 | 3 | 7 | ||
| 3 | 1 |
Cursed, lmao.
Having consecutive numbers just makes checking which numbers have and haven’t been used significantly faster.
Anyway, all this is to say – remind yourself to not get too lost in the numbers sometimes. They’re great for us as humans; we can use them as a crux to speed up a lot of logic and facilitate intuition. But at the end of the day, they’re only a syntax for describing the true underlying logical constraints.
To truly feel a Skyscrapers puzzle, look past the numbers and immerse yourself in the abstract structure hidden within.