problem0037

package
v0.0.0-...-d3fc627 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 0 Imported by: 0

README

37. Sudoku Solver

题目

Write a program to solve a Sudoku puzzle by filling the empty cells.

Empty cells are indicated by the character '.'.

You may assume that there will be only one unique solution.

problem

A sudoku puzzle...

solution

...and its solution numbers marked in red.

解题思路

我把数独框中,需要保证数字不重复的3×3小块,称为一个block。 由于数独需要保持每行,每列,每个block中的数字不重复。解题思路如下:

  1. 依次往9个block中,分别填写1~9。
  2. 如果block中已经存在n了,去填写下一个数。
  3. 在可行的空位填好 n 后
    1. 如果后面的填写没有问题,返回true
    2. 如果后面的填写有问题,把n移入下一个可行的位置。
      1. n在这个block中,没有位置放了,返回false
  4. 1~9都填写完了,就去填写下一个block分别填写1~9
  5. 所有的block都填写完了,结束。

具体过程和细节,见程序及注释。

总结

虽然,我一直主张编写不超过20行的函数,但是匿名函数确实好用。

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL