Skyscraper puzzle solver

Type the clues of your skyscraper puzzle around the grid and the solver fills in every building, then tells you whether that answer is the only one.

Type the clues in the outer ring (how many buildings are seen from that side) and any heights already given in the grid. Leave a box empty when there is no clue. Arrow keys move between boxes.

Solver

Examples (each has exactly one solution)

How to use the skyscraper puzzle solver

This skyscraper puzzle solver fills in any skyscraper grid from 3 by 3 to 9 by 9. Choose the size, type each clue in the ring around the grid and any heights that are already printed inside it, then press Solve. The answer appears in gray and the solver tells you whether it is the only one. Leave a box empty when there is no clue on that side.

The rules

Each cell holds a building with a height from 1 to the size of the grid, and every height appears exactly once in each row and each column, as in a Latin square or a sudoku without boxes. A clue outside the grid says how many buildings you see looking along that row or column from that side: a taller building hides every lower building behind it.

  • A clue of 1 means the tallest building stands right next to the clue.
  • A clue equal to the size of the grid (5 on a 5 by 5) means the heights rise one by one: 1, 2, 3, 4, 5 from that side.
  • The tallest building is seen from both ends, so two opposite clues add up to at most the size plus one. The solver points out clue pairs that break this, and two 1 clues at both ends of the same line.

Worked example

On a 4 by 4 grid, a row with the clue 4 on the left must read 1, 2, 3, 4. A row with the clue 3 on the left and 2 on the right has the 4 somewhere in the middle: from the left you see three buildings, so the 4 is in the third or fourth cell, and from the right you see two, so the 4 is not at the right end. That leaves 4 in the third cell with the first two cells rising, so the row is 1 2 4 3, 1 3 4 2 or 2 3 4 1. Column clues then decide which one. Load the 4 by 4 example to see a complete puzzle of this kind solved.

Is the answer unique?

The solver keeps looking after the first answer. If a second filling also fits every clue, you get both, with the cells where they differ highlighted, which usually means a clue is missing or was typed on the wrong side. If no filling fits, it says so; that often comes from a clue typed in the wrong box. Every answer is checked before it is shown: each row and column holds every height once, each clue counts the right number of visible buildings, and the given heights are kept.

How the solver works

For each row and each column the solver starts from the list of every order of the heights (24 orders on a 4 by 4, 362,880 on a 9 by 9) and keeps only the orders that match that line's two clues. Each cell can then only hold heights that still appear at that position in both its row's list and its column's list, and each list keeps only orders that agree with those cell options. This repeats until nothing changes. If a line still has more than one order left, the solver tries each of the orders of the line with the fewest left and repeats. Our test suite checks the solver against a brute force over all 576 Latin squares of size 4 and all 161,280 of size 5, and requires the same number of answers for every clue set.

Tips for solving by hand

Start with the clues 1 and n, then the high clues (n minus 1 forces the tallest building into the last cell or the one before), then lines with clues on both ends. Write the possible heights small in each cell and cross them out as rows and columns fill up.

Want to play one? The skyscrapers puzzle page makes new 4x4 to 6x6 cities with a daily puzzle.

Solver tested . Found a problem? Tell us.

Questions

What does the number outside a skyscraper puzzle mean?

It is how many buildings you can see from that side of the row or column. Taller buildings hide shorter ones behind them, so a 1 means the tallest building is first and the highest clue means the heights go up one by one.

Can two clues on the same row add up to more than the size plus one?

No. The tallest building is visible from both ends and counts in both clues, so on an n by n grid two opposite clues add up to at most n + 1. The solver flags clue pairs that break this.

Why does the solver find two solutions?

The clues you typed do not pin the grid down. Puzzles in books and apps have exactly one answer, so a second solution usually means a clue is missing or sits in the wrong box. The highlighted cells show where the two answers differ.

Does it handle puzzles with heights already given in the grid?

Yes. Type the given heights in the inner cells; the solver keeps them and they count in the uniqueness check.

What sizes can it solve?

From 3 by 3 to 9 by 9. Each example on this page, up to 9 by 9, is solved and proved unique in under a second on a laptop.