I’ve stopped reacting to everything that…

macain

Republican Sen. John McCain at time 00:40.


“A long time ago, honestly, I’ve stopped reacting to everything that the President has stated and try to work on the issues and the people who he is going to surround himself with, who I am very pleased with as far as national security is concerned.”

http://edition.cnn.com/2017/01/24/politics/mccain-no-evidence-of-illegal-voting-cnntv/index.html

Alternative facts

conway
http://www.nbcnews.com/meet-the-press/video/conway-press-secretary-gave-alternative-facts-860142147643

Washington (CNN) — White House press secretary Sean Spicer’s false claims about the size of the crowd at President Donald Trump’s inauguration were “alternative facts,” a top Trump aide said Sunday.

atlantic
https://www.theatlantic.com/politics/archive/2017/01/inauguration-crowd-size/514058/

Well, we all expected this to happen, didn’t we?

COCA: Vibroplex

vibroplex

Let’s try using COCA with some the words or phrases familiar to us.

vibroplex2

We receive only three search results, but two of them are quite interesting.

I didn’t like this guy because he used a Vibroplex semi-automatic speed key and sent his messages too fast. He had a lousy ” fist. ” His dashes were too short — you could easily take them for dots — and his spacing between word groups was erratic. He also bragged too much about his rig. A thousand watts generated by a pair of big Eimac tetrodes in the final amplifier. Anybody could do that if they had the money.

He told me that since his stroke, he’d felt as if he were trapped in the radio room with the door locked from the outside. The receiver was still working, but the transmitter was broken. He couldn’t talk back to anyone. He’d been tapping away with a spoon for days, even though he’d given up hope of being ” rescued. ” Paralysis of his right side had prevented him from writing any messages. # I brought to the hospital an old Vibroplex Sidewinder telegraph key, which was Harry’s favorite for sending Morse code. Harry had spent a good part of his life on oceangoing freighters as a radiotelegraph operator. He told me a story of something that had happened at sea several days before the attack on Pearl Harbor.

COCA

coca1

COCA, the Corpus of Contemporary American English, is the largest freely-available corpus of English.

coca2

Enter the phrase you wish to search, and you will get the results immediately.

coca3

UIKit and SpriteKit (3)

No fancy animations yet, but it is playable.

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: cookiesLayer)
        let (success, col, row) = convertPoint(location)
        if success {
            if level.getTableAt(col: col, row: row) == 0 { // an empty place is selected, so highlight it.
                rowSelected = row
                colSelected = col
                if selectedSprite != nil {
                    selectedSprite.run(SKAction.removeFromParent())
                }
                selectedSprite = SKSpriteNode(imageNamed: "Undef-Highlighted")
                selectedSprite.size = CGSize(width: TileWidth, height: TileHeight)
                selectedSprite.position = pointFor(col: colSelected, row: rowSelected)
                selectedLayer.addChild(selectedSprite)
                showCandidate(col: colSelected, row: rowSelected)
            } else if row == 10 { // number selected
                numberSelected = true
                numberToMove = col + 1
                if level.isSafeForNum(col: colSelected, row: rowSelected, num: numberToMove) {
                    level.setTableAt(col: colSelected, row: rowSelected, val: numberToMove)
                    let sprite = SKSpriteNode(imageNamed: spriteNames[numberToMove]+"-Highlighted")
                    sprite.size = CGSize(width: TileWidth, height: TileHeight)
                    sprite.position = pointFor(col: colSelected, row: rowSelected)
                    userLayer.addChild(sprite)
                    level.setTableAt(col: colSelected, row: rowSelected, val: -numberToMove)
                    if selectedSprite != nil {
                        selectedSprite.run(SKAction.removeFromParent())
                    }
                }
            } else if level.getTableAt(col: col, row: row ) < 0 { // cancel move
                rowSelected = row
                colSelected = col
                level.setTableAt(col: col, row: row, val: 0)
                let location = touch.location(in: self)
                let sprite: SKNode? = atPoint(location)
                sprite?.run(SKAction.removeFromParent())
                if selectedSprite != nil {
                    selectedSprite.run(SKAction.removeFromParent())
                }
                selectedSprite = SKSpriteNode(imageNamed: "Undef-Highlighted")
                selectedSprite.size = CGSize(width: TileWidth, height: TileHeight)
                selectedSprite.position = pointFor(col: col, row: row)
                selectedLayer.addChild(selectedSprite)
                showCandidate(col: col, row: row)
            }
        }
    }

The code is very ugly.

UIKit and SpriteKit (2)

If you click on an empty place, you will see which numbers can be selected for the place.

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: cookiesLayer)
        let (success, column, row) = convertPoint(location)
        if success && level.tableAt(column: column, row: row) == 0 {
            if row_touchedb4 >= 0 { // not the first time, recover to the original state
                let num = level.tableAt(column: column_touchedb4, row: row_touchedb4)
                print(row_touchedb4, column_touchedb4, num)
                let sprite = SKSpriteNode(imageNamed: spriteNames[num])
                sprite.size = CGSize(width: TileWidth, height: TileHeight)
                sprite.position = pointFor(column: column_touchedb4, row: row_touchedb4)
                cookiesLayer.addChild(sprite)
                selectionSprite.run(SKAction.removeFromParent())
            }
            column_touchedb4 = column
            row_touchedb4    = row
            let location = touch.location(in: self)
            let sprite: SKNode? = atPoint(location)
            sprite?.run(SKAction.removeFromParent())
            selectionSprite = SKSpriteNode(imageNamed: "Undef-Highlighted")
            selectionSprite.size = CGSize(width: TileWidth, height: TileHeight)
            selectionSprite.position = pointFor(column: column, row: row)
            cookiesLayer.addChild(selectionSprite)
            showCandidate(column: column, row: row)
 }

The code could be much better.

UIKit and SpriteKit

spritekit2

Nice looking GUIs are always welcomed especially when you are playing a game. So I am now trying to use UIKit and SpriteKit. The job is not obvious at all for me, but it would be fun if I can write some simple programs which run on iOS.

Number Place and Swift 3 (5)

backtrack3

If you are lucky, you may reach to the solution without any backtracking. This is particularly true in the cases you can find empty cells with only one possible move.

In the following list, the table on the left side shows the current arrangement of the numbers, a dot showing the place to be filled, while the table on the right side shows the number of possible moves. If you find a place with eval=1, you should first fill such places.

nplaces = 52 

index=0, Position(row: 1, col: 7), eval=1
-----------------   -----------------
7 . 3 . . . . . .   . 4 . 4 4 5 3 3 4 
. 5 1 3 7 . 4 . .   3 . . . . 4 . 1 3 
6 . . . 1 . . 2 .   . 3 2 4 . 3 3 . 5 
. . 4 6 . . . . .   4 6 . . 2 3 4 4 4 
. . . . . 7 . 8 .   3 5 3 3 2 . 4 . 5 
5 . . 2 3 1 9 . .   . 3 2 . . . . 2 3 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 4 
. . 7 . 9 . 2 . .   3 4 . 3 . 4 . 3 3 
-----------------   -----------------
index=1, Position(row: 5, col: 7), eval=1
-----------------   -----------------
7 . 3 . . . . . .   . 4 . 4 4 5 2 2 3 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 2 
6 . . . 1 . . 2 .   . 3 2 4 . 3 3 . 5 
. . 4 6 . . . . .   4 6 . . 2 3 4 4 4 
. . . . . 7 . 8 .   3 5 3 3 2 . 4 . 5 
5 . . 2 3 1 9 . .   . 3 2 . . . . 1 3 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 4 
. . 7 . 9 . 2 . .   3 4 . 3 . 4 . 2 3 
-----------------   -----------------
index=2, Position(row: 0, col: 6), eval=2
-----------------   -----------------
7 . 3 . . . . . .   . 4 . 4 4 5 2 2 3 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 2 
6 . . . 1 . . 2 .   . 3 2 4 . 3 3 . 5 
. . 4 6 . . . . .   4 6 . . 2 3 3 3 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 4 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 4 
. . 7 . 9 . 2 . .   3 4 . 3 . 4 . 2 3 
-----------------   -----------------
index=3, Position(row: 0, col: 7), eval=1
-----------------   -----------------
7 . 3 . . . 1 . .   . 4 . 4 4 5 . 1 3 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 2 
6 . . . 1 . . 2 .   . 3 2 4 . 3 3 . 5 
. . 4 6 . . . . .   4 6 . . 2 3 2 3 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 4 
. . 7 . 9 . 2 . .   3 4 . 3 . 4 . 2 3 
-----------------   -----------------
index=4, Position(row: 8, col: 7), eval=1
-----------------   -----------------
7 . 3 . . . 1 5 .   . 4 . 3 3 4 . . 2 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 2 
6 . . . 1 . . 2 .   . 3 2 4 . 3 2 . 4 
. . 4 6 . . . . .   4 6 . . 2 3 2 2 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 4 
. . 7 . 9 . 2 . .   3 4 . 3 . 4 . 1 3 
-----------------   -----------------
index=5, Position(row: 3, col: 7), eval=1
-----------------   -----------------
7 . 3 . . . 1 5 .   . 4 . 3 3 4 . . 2 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 2 
6 . . . 1 . . 2 .   . 3 2 4 . 3 2 . 4 
. . 4 6 . . . . .   4 6 . . 2 3 2 1 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 3 
. . 7 . 9 . 2 3 .   3 4 . 3 . 3 . . 2 
-----------------   -----------------
index=6, Position(row: 0, col: 8), eval=2
-----------------   -----------------
7 . 3 . . . 1 5 .   . 4 . 3 3 4 . . 2 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 2 
6 . . . 1 . . 2 .   . 3 2 4 . 3 2 . 4 
. . 4 6 . . . 1 .   3 5 . . 2 3 2 . 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 3 
. . 7 . 9 . 2 3 .   3 4 . 3 . 3 . . 2 
-----------------   -----------------
index=7, Position(row: 1, col: 8), eval=1
-----------------   -----------------
7 . 3 . . . 1 5 8   . 3 . 2 2 3 . . . 
. 5 1 3 7 . 4 6 .   3 . . . . 3 . . 1 
6 . . . 1 . . 2 .   . 3 2 4 . 3 2 . 3 
. . 4 6 . . . 1 .   3 5 . . 2 3 2 . 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 3 
. . 7 . 9 . 2 3 .   3 4 . 3 . 3 . . 2 
-----------------   -----------------
index=8, Position(row: 0, col: 3), eval=2
-----------------   -----------------
7 . 3 . . . 1 5 8   . 3 . 2 2 3 . . . 
. 5 1 3 7 . 4 6 9   2 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 4 . 3 2 . 2 
. . 4 6 . . . 1 .   3 5 . . 2 3 2 . 3 
. . . . . 7 . 8 .   3 5 3 3 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 3 
. . 7 . 9 . 2 3 .   3 4 . 3 . 3 . . 2 
-----------------   -----------------
index=9, Position(row: 0, col: 4), eval=1
-----------------   -----------------
7 . 3 4 . . 1 5 8   . 2 . . 1 3 . . . 
. 5 1 3 7 . 4 6 9   2 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 3 . 3 2 . 2 
. . 4 6 . . . 1 .   3 5 . . 2 3 2 . 3 
. . . . . 7 . 8 .   3 5 3 2 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 2 3 . . 3 
. . 7 . 9 . 2 3 .   3 4 . 3 . 3 . . 2 
-----------------   -----------------
index=10, Position(row: 7, col: 4), eval=1
-----------------   -----------------
7 . 3 4 6 . 1 5 8   . 2 . . . 2 . . . 
. 5 1 3 7 . 4 6 9   2 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 3 . 3 2 . 2 
. . 4 6 . . . 1 .   3 5 . . 2 3 2 . 3 
. . . . . 7 . 8 .   3 5 3 2 2 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 3 . . 3 . . 
. . . . . . 8 4 .   3 4 4 3 1 3 . . 3 
. . 7 . 9 . 2 3 .   3 4 . 3 . 3 . . 2 
-----------------   -----------------
index=11, Position(row: 3, col: 4), eval=1
-----------------   -----------------
7 . 3 4 6 . 1 5 8   . 2 . . . 2 . . . 
. 5 1 3 7 . 4 6 9   2 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 3 . 3 2 . 2 
. . 4 6 . . . 1 .   3 5 . . 1 3 2 . 3 
. . . . . 7 . 8 .   3 5 3 2 1 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 4 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   3 4 . 2 . 2 . . 2 
-----------------   -----------------
index=12, Position(row: 4, col: 4), eval=1
-----------------   -----------------
7 . 3 4 6 . 1 5 8   . 2 . . . 2 . . . 
. 5 1 3 7 . 4 6 9   2 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 3 . 3 2 . 2 
. . 4 6 8 . . 1 .   2 4 . . . 2 2 . 3 
. . . . . 7 . 8 .   3 5 3 2 1 . 3 . 5 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 4 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   3 4 . 2 . 2 . . 2 
-----------------   -----------------
index=13, Position(row: 0, col: 1), eval=2
-----------------   -----------------
7 . 3 4 6 . 1 5 8   . 2 . . . 2 . . . 
. 5 1 3 7 . 4 6 9   2 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 3 . 3 2 . 2 
. . 4 6 8 . . 1 .   2 4 . . . 2 2 . 3 
. . . . 4 7 . 8 .   3 5 3 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 4 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   3 4 . 2 . 2 . . 2 
-----------------   -----------------
index=14, Position(row: 0, col: 5), eval=1
-----------------   -----------------
7 2 3 4 6 . 1 5 8   . . . . . 1 . . . 
. 5 1 3 7 . 4 6 9   1 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 3 . 3 2 . 2 
. . 4 6 8 . . 1 .   2 3 . . . 2 2 . 3 
. . . . 4 7 . 8 .   3 4 3 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   3 4 . 2 . 2 . . 2 
-----------------   -----------------
index=15, Position(row: 1, col: 0), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
. 5 1 3 7 . 4 6 9   1 . . . . 2 . . . 
6 . . . 1 . . 2 .   . 3 2 2 . 2 2 . 2 
. . 4 6 8 . . 1 .   2 3 . . . 1 2 . 3 
. . . . 4 7 . 8 .   3 4 3 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   3 4 . 2 . 2 . . 2 
-----------------   -----------------
index=16, Position(row: 1, col: 5), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 . 4 6 9   . . . . . 1 . . . 
6 . . . 1 . . 2 .   . 2 1 2 . 2 2 . 2 
. . 4 6 8 . . 1 .   2 3 . . . 1 2 . 3 
. . . . 4 7 . 8 .   3 4 3 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 4 . 2 . 2 . . 2 
-----------------   -----------------
index=17, Position(row: 2, col: 2), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 . . . 1 . . 2 .   . 2 1 2 . 2 2 . 2 
. . 4 6 8 . . 1 .   2 3 . . . 1 2 . 3 
. . . . 4 7 . 8 .   3 4 3 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 3 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 4 . 2 . 2 . . 2 
-----------------   -----------------
index=18, Position(row: 2, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 . 9 . 1 . . 2 .   . 1 . 2 . 2 2 . 2 
. . 4 6 8 . . 1 .   2 3 . . . 1 2 . 3 
. . . . 4 7 . 8 .   3 4 2 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 4 . 2 . 2 . . 2 
-----------------   -----------------
index=19, Position(row: 3, col: 5), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 . 1 . . 2 .   . . . 2 . 2 2 . 2 
. . 4 6 8 . . 1 .   2 3 . . . 1 2 . 3 
. . . . 4 7 . 8 .   3 4 2 2 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 2 . . 2 
-----------------   -----------------
index=20, Position(row: 2, col: 5), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 . 1 . . 2 .   . . . 2 . 1 2 . 2 
. . 4 6 8 5 . 1 .   2 3 . . . . 1 . 2 
. . . . 4 7 . 8 .   3 4 2 1 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 2 . . 2 
-----------------   -----------------
index=21, Position(row: 2, col: 3), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 . 1 8 . 2 .   . . . 1 . . 2 . 2 
. . 4 6 8 5 . 1 .   2 3 . . . . 1 . 2 
. . . . 4 7 . 8 .   3 4 2 1 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=22, Position(row: 3, col: 6), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 . 2 .   . . . . . . 2 . 2 
. . 4 6 8 5 . 1 .   2 3 . . . . 1 . 2 
. . . . 4 7 . 8 .   3 4 2 1 . . 3 . 4 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=23, Position(row: 2, col: 6), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 . 2 .   . . . . . . 1 . 2 
. . 4 6 8 5 3 1 .   2 2 . . . . . . 1 
. . . . 4 7 . 8 .   3 4 2 1 . . 2 . 3 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 3 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=24, Position(row: 2, col: 8), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 .   . . . . . . . . 1 
. . 4 6 8 5 3 1 .   2 2 . . . . . . 1 
. . . . 4 7 . 8 .   3 4 2 1 . . 2 . 3 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=25, Position(row: 3, col: 8), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
. . 4 6 8 5 3 1 .   2 2 . . . . . . 1 
. . . . 4 7 . 8 .   3 4 2 1 . . 2 . 3 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=26, Position(row: 3, col: 0), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
. . 4 6 8 5 3 1 2   1 2 . . . . . . . 
. . . . 4 7 . 8 .   3 4 2 1 . . 2 . 2 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   3 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=27, Position(row: 3, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 . 4 6 8 5 3 1 2   . 1 . . . . . . . 
. . . . 4 7 . 8 .   2 3 2 1 . . 2 . 2 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   2 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=28, Position(row: 4, col: 3), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . . . 4 7 . 8 .   2 3 2 1 . . 2 . 2 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   2 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=29, Position(row: 8, col: 5), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . . 9 4 7 . 8 .   2 3 2 . . . 2 . 2 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   2 3 2 2 . 2 . . 2 
. . 7 . 9 . 2 3 .   2 3 . 2 . 1 . . 2 
-----------------   -----------------
index=30, Position(row: 7, col: 5), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . . 9 4 7 . 8 .   2 3 2 . . . 2 . 2 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 . 8 4 .   2 3 2 2 . 1 . . 2 
. . 7 . 9 6 2 3 .   2 2 . 2 . . . . 1 
-----------------   -----------------
index=31, Position(row: 8, col: 8), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . . 9 4 7 . 8 .   2 3 2 . . . 2 . 2 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 2 . . 
. . . . 5 3 8 4 .   2 3 2 2 . . . . 2 
. . 7 . 9 6 2 3 .   2 2 . 2 . . . . 1 
-----------------   -----------------
index=32, Position(row: 4, col: 8), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . . 9 4 7 . 8 .   2 3 2 . . . 2 . 1 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 2 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   2 3 2 2 . . . . 2 
. . 7 . 9 6 2 3 5   2 2 . 2 . . . . . 
-----------------   -----------------
index=33, Position(row: 4, col: 2), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . . 9 4 7 . 8 6   2 2 1 . . . 1 . . 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 1 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   2 3 2 2 . . . . 1 
. . 7 . 9 6 2 3 5   2 2 . 2 . . . . . 
-----------------   -----------------
index=34, Position(row: 4, col: 0), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
. . 2 9 4 7 . 8 6   1 2 . . . . 1 . . 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 1 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   2 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   2 2 . 2 . . . . . 
-----------------   -----------------
index=35, Position(row: 4, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 . 2 9 4 7 . 8 6   . 1 . . . . 1 . . 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 1 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   1 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 2 . 2 . . . . . 
-----------------   -----------------
index=36, Position(row: 4, col: 6), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 . 8 6   . . . . . . 1 . . 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 1 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   1 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 2 . 2 . . . . . 
-----------------   -----------------
index=37, Position(row: 5, col: 8), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 . . 2 3 1 9 7 .   . 2 2 . . . . . 1 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   1 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 2 . 2 . . . . . 
-----------------   -----------------
index=38, Position(row: 6, col: 6), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 . . 2 3 1 9 7 4   . 2 2 . . . . . . 
3 . . . 2 4 . 9 1   . 2 3 2 . . 1 . . 
. . . . 5 3 8 4 .   1 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 2 . 2 . . . . . 
-----------------   -----------------
index=39, Position(row: 6, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 . . 2 3 1 9 7 4   . 2 2 . . . . . . 
3 . . . 2 4 6 9 1   . 1 2 2 . . . . . 
. . . . 5 3 8 4 .   1 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 2 . 2 . . . . . 
-----------------   -----------------
index=40, Position(row: 5, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 . . 2 3 1 9 7 4   . 1 2 . . . . . . 
3 8 . . 2 4 6 9 1   . . 1 1 . . . . . 
. . . . 5 3 8 4 .   1 3 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=41, Position(row: 5, col: 2), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 . 2 3 1 9 7 4   . . 1 . . . . . . 
3 8 . . 2 4 6 9 1   . . 1 1 . . . . . 
. . . . 5 3 8 4 .   1 2 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=42, Position(row: 6, col: 2), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 . . 2 4 6 9 1   . . 1 1 . . . . . 
. . . . 5 3 8 4 .   1 2 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=43, Position(row: 6, col: 3), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 . 2 4 6 9 1   . . . 1 . . . . . 
. . . . 5 3 8 4 .   1 2 1 2 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=44, Position(row: 7, col: 0), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
. . . . 5 3 8 4 .   1 2 1 1 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=45, Position(row: 7, col: 2), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 . . . 5 3 8 4 .   . 2 1 1 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=46, Position(row: 7, col: 3), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 . 6 . 5 3 8 4 .   . 2 . 1 . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 2 . . . . . 
-----------------   -----------------
index=47, Position(row: 7, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 . 6 1 5 3 8 4 .   . 1 . . . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 1 . . . . . 
-----------------   -----------------
index=48, Position(row: 7, col: 8), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 9 6 1 5 3 8 4 .   . . . . . . . . 1 
. . 7 . 9 6 2 3 5   1 1 . 1 . . . . . 
-----------------   -----------------
index=49, Position(row: 8, col: 0), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 9 6 1 5 3 8 4 7   . . . . . . . . . 
. . 7 . 9 6 2 3 5   1 1 . 1 . . . . . 
-----------------   -----------------
index=50, Position(row: 8, col: 1), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 9 6 1 5 3 8 4 7   . . . . . . . . . 
4 . 7 . 9 6 2 3 5   . 1 . 1 . . . . . 
-----------------   -----------------
index=51, Position(row: 8, col: 3), eval=1
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 9 6 1 5 3 8 4 7   . . . . . . . . . 
4 1 7 . 9 6 2 3 5   . . . 1 . . . . . 
-----------------   -----------------
done
-----------------   -----------------
7 2 3 4 6 9 1 5 8   . . . . . . . . . 
8 5 1 3 7 2 4 6 9   . . . . . . . . . 
6 4 9 5 1 8 7 2 3   . . . . . . . . . 
9 7 4 6 8 5 3 1 2   . . . . . . . . . 
1 3 2 9 4 7 5 8 6   . . . . . . . . . 
5 6 8 2 3 1 9 7 4   . . . . . . . . . 
3 8 5 7 2 4 6 9 1   . . . . . . . . . 
2 9 6 1 5 3 8 4 7   . . . . . . . . . 
4 1 7 8 9 6 2 3 5   . . . . . . . . . 
-----------------   -----------------

You can try the code by yourself at IBM Swift Sandbox.

struct Position {
    var row: Int = -1
    var col: Int = -1
}
struct Place {
    var position = Position()
    var val: Int = 0
}

class NumBoard {
    var table         = [[Int]]()
    var tableEval     = [[Int]](repeating:[Int](repeating:99, count:9), count:9)
    var emptyPlaces   = [Place]()
    var sortedPlaces  = [Place]()
    var putPositions  = [Position]()
    var position      = Position()
    var place         = Place()
    var nplaces : Int = 0
    
    init() {
        table = [[7,0,3, 0,0,0, 0,0,0],
                 [0,5,1, 3,7,0, 4,0,0],
                 [6,0,0, 0,1,0, 0,2,0],
                 [0,0,4, 6,0,0, 0,0,0],
                 [0,0,0, 0,0,7, 0,8,0],
                 [5,0,0, 2,3,1, 9,0,0],
                 [3,0,0, 0,2,4, 0,9,1],
                 [0,0,0, 0,0,0, 8,4,0],
                 [0,0,7, 0,9,0, 2,0,0]]

        for rr in 0...8 {
            for cc in 0...8 {
                if table[rr][cc] == 0 {
                    nplaces += 1
                    position.row = rr
                    position.col = cc
                    tableEval[rr][cc] = eval(position: position)
                }
            }
        }
        print("nplaces = \(nplaces) \n")
    }

    func myprint2(table: [[Int]], table2: [[Int]]) {
        print("-----------------   -----------------")
        for rr in 0...8 {
            for cc in 0...8 {
                if table[rr][cc] >= 1 && table[rr][cc] <= 9 {
                    print(table[rr][cc], terminator: " ")
                } else {
                    print(".", terminator: " ")
                }
            }
            print("  ", terminator: "")
            for cc in 0...8 {
                if table2[rr][cc] >= 1 && table2[rr][cc] <= 9 {
                    print(table2[rr][cc], terminator: " ")
                } else {
                    print(".", terminator: " ")
                }
            }
            print("")
        }
        print("-----------------   -----------------")
    }

    func eval(position: Position) -> Int {
        var count = 0
        for num in 1...9 {
            if isSafeForNum(position: position, num: num) {
                count += 1
            }
        }
        return count
    }
    
    func isSafeForNum(position: Position, num: Int) -> Bool {
        for rr in 0...8 {
            if num == table[rr][position.col] { return false }
        }
        for cc in 0...8 {
            if num == table[position.row][cc] { return false }
        }
        let rowBase = (position.row / 3) * 3
        let colBase = (position.col / 3) * 3
        for rr in 0...2 {
            for cc in 0...2 {
                if num == table[rowBase+rr][colBase+cc] { return false }
            }
        }
        return true
    }

    func findPosition() -> Position {
        var minVal = 99
        var position = Position()
        for rr in 0...8 {
            for cc in 0...8 {
                if tableEval[rr][cc] < minVal {
                    minVal = tableEval[rr][cc]
                    position.row = rr
                    position.col = cc
                }
            }
        }
        return position
    }
    
    func update(position: Position) {
        let row = position.row
        let col = position.col
        var pos = Position()
        tableEval[row][col] = 99
        for rr in 0...8 {
            if rr != row && table[rr][col] == 0 {
                pos.row = rr
                pos.col = col
                tableEval[rr][col] = eval(position: pos)
            }
        }
        for cc in 0...8 {
            if cc != col && table[row][cc] == 0 {
                pos.row = row
                pos.col = cc
                tableEval[row][cc] = eval(position: pos)
            }
        }
        let rowBase = (row / 3) * 3
        let colBase = (col / 3) * 3
        let rowOffset = row - rowBase
        let colOffset = col - colBase
        for rr in 0...2 {
            for cc in 0...2 {
                if rr != rowOffset && cc != colOffset && table[rr+rowBase][cc+colBase] == 0 {
                    pos.row = rr + rowBase
                    pos.col = cc + colBase
                    tableEval[pos.row][pos.col] = eval (position: pos)
                }
            }
        }
    }

    func dropNum(index: Int) {
        position = findPosition()
        print("index=\(index), \(position), eval=\(tableEval[position.row][position.col])")
        myprint2(table: table, table2: tableEval)
        for num in 1...9 {
            if isSafeForNum(position: position, num: num) {
                table[position.row][position.col] = num
                putPositions.append(position)
                update(position: position)
                if putPositions.count == nplaces { return }
                dropNum(index: index+1)
                if putPositions.count != nplaces {
                    position = putPositions[putPositions.count - 1]
                    table[position.row][position.col] = 0
                    putPositions.removeLast()
                    update(position: position)
                }
            }
        }
    }
    
    func play() {
        dropNum(index: 0)
        print("done")
        myprint2(table: table, table2: tableEval)
    }
}

// main program
let myboard = NumBoard()
myboard.play()

The program is somewhat redundant, but easy to read, I suppose.

Number Place and Swift 3 (4)

backtrack2

Of course, we do not select the position to be filled randomly or sequentially, but more intelligently to save our energy. One method is to select the place with minimum number of possibilities.

    func findPosition(table: [[Int]]) -> Position {
        var workPlaces   = [Place]()
        var sortedPlaces = [Place]()
        var position = Position()
        var place = Place()
            for cc in 0...8 {
                for rr in 0...8 {
                if table[rr][cc] == 0 {
                    position.row = rr
                    position.col = cc
                    place.position = position
                    place.val    = eval(position: position, table: table)
                    workPlaces.append(place)
                }
            }
        }
        sortedPlaces = workPlaces.sorted( by: { $0.val < $1.val } )
        place = sortedPlaces[0]
        position = place.position
        return position
    }

Actually, there is no need to reevaluate the all positions every time. Only those affected by the last move should be considered.

backtrac3

The recursive function, dropNum is now called only 139 times with the same problem.

struct Position {
    var row: Int = -1
    var col: Int = -1
}
struct Place {
    var position = Position()
    var val: Int = 0
}

class NumBoard {
    var table         = [[Int]]()
    var emptyPlaces   = [Place]()
    var sortedPlaces  = [Place]()
    var putPositions  = [Position]()
    var position      = Position()
    var place         = Place()
    var nplaces : Int = 0
    
    init() {
        table = [[7,0,3, 0,0,0, 0,0,0],
                 [0,5,1, 3,7,0, 4,0,0],
                 [6,0,0, 0,1,0, 0,2,0],
                 [0,0,4, 6,0,0, 0,0,0],
                 [0,0,0, 0,0,7, 0,8,0],
                 [5,0,0, 2,3,1, 9,0,0],
                 [3,0,0, 0,2,4, 0,9,1],
                 [0,0,0, 0,0,0, 8,4,0],
                 [0,0,7, 0,9,0, 2,0,0]]

        for rr in 0...8 {
            for cc in 0...8 {
                if table[rr][cc] == 0 {
                    nplaces += 1
                }
            }
        }
        myprint(table: table)
        print("nplaces = \(nplaces)")
    }
    
    func myprint(table: [[Int]]) {
        print("-----------------")
        for rr in 0...8 {
            for cc in 0...8 {
                if table[rr][cc] == 0 {
                    print(".", terminator: " ")
                } else {
                    print(table[rr][cc], terminator: " ")
                }
            }
            print("")
        }
        print("-----------------")
    }
    
    func eval(position: Position, table: [[Int]]) -> Int {
        var count = 0
        for num in 1...9 {
            if isSafeForNum(position: position, num: num) {
                count += 1
            }
        }
        return count
    }
    
    func isSafeForNum(position: Position, num: Int) -> Bool {
        for rr in 0...8 {
            if num == table[rr][position.col] { return false }
        }
        for cc in 0...8 {
            if num == table[position.row][cc] { return false }
        }
        let rowBase = (position.row / 3) * 3
        let colBase = (position.col / 3) * 3
        for rr in 0...2 {
            for cc in 0...2 {
                if num == table[rowBase+rr][colBase+cc] { return false }
            }
        }
        return true
    }

    func findPosition(table: [[Int]]) -> Position {
        var workPlaces   = [Place]()
        var sortedPlaces = [Place]()
        var position = Position()
        var place = Place()
            for cc in 0...8 {
                for rr in 0...8 {
                if table[rr][cc] == 0 {
                    position.row = rr
                    position.col = cc
                    place.position = position
                    place.val    = eval(position: position, table: table)
                    workPlaces.append(place)
                }
            }
        }
        sortedPlaces = workPlaces.sorted( by: { $0.val < $1.val } )
        place = sortedPlaces[0]
        position = place.position
        return position
    }
    
    func dropNum(index: Int) {
        position = findPosition(table: table)
        for num in 1...9 {
            if isSafeForNum(position: position, num: num) {
                table[position.row][position.col] = num
                putPositions.append(position)
                if putPositions.count == nplaces { return }
                dropNum(index: index+1)
                if putPositions.count != nplaces {
                    position = putPositions[putPositions.count - 1]
                    table[position.row][position.col] = 0
                    putPositions.removeLast()
                }
            }
        }
    }
    
    func play() {
        dropNum(index: 0)
        myprint(table: table)
    }
}

// main program
let myboard = NumBoard()
myboard.play()