Why is this Sudoku Skyscraper Failing?

I'm attempting to write a program that solves Sudoku puzzles using a variety of techniques. Up this point, I've only implemented naked singles and hidden singles (for rows and columns). I've been trying to implement the Skyscraper technique, but when solving by hand, I've been having trouble getting it to work particularly for this puzzle:

The program solves it up to this point:

When I attempt the following Skyscraper by hand, I eliminate the 9 for a naked 5, and thus fill it in...

But the completed puzzle is as follows...

Why is this? Is there some parameter of the Skyscraper technique that my structure isn't meeting? What about in the following case, where I create a Skyscraper structure under just about the same conditions as the first scenario, thus yielding a naked 7, which is the correct value for the green cell. How come the first Skyscraper didn't work?

• What's wrong with the completed puzzle? – greenturtle3141 Oct 30 '16 at 19:54
• Those aren't skyscrapers. A skyscraper means the red cells are the only two cells in their respective columns to contain a 9 as possibility. But there are more cells in their columns that contain a 9. In the 2nd example, same thing: the red cells aren't the only ones that contain a 7. It's not a skyscraper. – Dennis_E Oct 30 '16 at 20:31
• @Dennis_E Thank you for your input. I see now why they are not skyscraper structures! – Zulfe Oct 30 '16 at 20:59
• With all these techniques, it's important to understand why you can eliminate numbers. – Dennis_E Oct 30 '16 at 21:09

I think that

For a skyscraper (a type of x-wing) the values ($9$ in this case) must only occur twice amongst the pencil marks in two rows (or columns).
Hence your "by hand" execution is incorrect

Also note that there is

a hidden single $7$ in the top row, fourth column (only 7 left in the nonet) which your solver should find first.

And that

using only hidden and naked singles should get to this point: 6 1 2 | 7 . 8 | . . . 9 5 3 | 4 1 2 | 6 7 8 8 7 4 | 3 . 6 | . . 1 ------+-------+------ 2 8 1 | 5 6 . | . 9 . 4 9 7 | 2 8 3 | 1 6 5 5 3 6 | 1 . . | 8 . . ------+-------+------ 3 2 8 | 6 7 . | . 1 9 7 6 . | . . 1 | . . . 1 4 . | . . . | 7 . 6
whereupon you should find three different naked pairs (something you don't say you've implemented but which is simpler) removing pencil marks for $5$ and $9$ from four of the cells in the lower half. The naked pair of the $5,9$ in the middle column leaves a naked single $4$ in the sixth row, middle column, whereupon naked singles will finish to the solution posted.

• Thank you so much for your answer! I've yet to implement the finding of hidden singles in blocks, which clearly needs to be done. I'll also look into naked pairs! – Zulfe Oct 30 '16 at 21:00
• See sudokuwiki.org for a similar type of solver (logical, pattern based step by step), and a strategy overview (which does not have "skyscraper" itself). Even that solver wont solve some sudoku. There is a program called SudokuExplainer which will - but the end result for very tough sudoku is fairly long inference chains. A member here, 2012rCampion also has created a solver which only does that and I have created one which gives no reasoning (using dancing links). – Jonathan Allan Oct 30 '16 at 21:09
• You can see the set of deductions my old Sudoku solver made for this problem here. – David Schwartz Oct 30 '16 at 23:38