Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: solve sudoku puzzle #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: solve sudoku puzzle #1

wants to merge 1 commit into from

Conversation

MrHeer
Copy link
Member

@MrHeer MrHeer commented Oct 24, 2022

No description provided.

"""Make a random puzzle with N or more assignments. Restart on contradictions.
Note the resulting puzzle is not guaranteed to be solvable, but empirically
about 99.8% of them are solvable. Some have multiple solutions."""
values = dict((s, digits) for s in squares)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是一个重复计算的值?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么叫重复计算的值?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是一个常量,只要计算一次即可。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道你在说什么

@thomaszdxsn
Copy link
Collaborator

我觉得这个写法需要更加 readable,比如和 gameplay 一样使用 number[][] 作为数据结构。

  1. 这里的函数可以用于之后的验证;比如用户填入一个值之后验证是否违反了 sudoku 的规则
  2. 作者原来使用 string 类型的原因是因为他觉得二维数组需要 deepcopy 开销比较高。但是这个二维数组的 size 并不算大,无非是 9*9 的规模。没有必要在这种地方优化,换成更容易阅读的方式显然更好
  3. 如果更换了数据结构,那么每个 cell 的坐标也能使用 (number, number) 的 tuple 结构。这种数据结构比 A1 的写法要方便多了,A1, C6 写法对于非英语母语的人有识别难度。

@MrHeer

@MrHeer
Copy link
Member Author

MrHeer commented Oct 31, 2022

我觉得这个写法需要更加 readable,比如和 gameplay 一样使用 number[][] 作为数据结构。

  1. 这里的函数可以用于之后的验证;比如用户填入一个值之后验证是否违反了 sudoku 的规则
  2. 作者原来使用 string 类型的原因是因为他觉得二维数组需要 deepcopy 开销比较高。但是这个二维数组的 size 并不算大,无非是 9*9 的规模。没有必要在这种地方优化,换成更容易阅读的方式显然更好
  3. 如果更换了数据结构,那么每个 cell 的坐标也能使用 (number, number) 的 tuple 结构。这种数据结构比 A1 的写法要方便多了,A1, C6 写法对于非英语母语的人有识别难度。

@MrHeer

  1. 里面有一个 solved 就是用来验证是否解决
  2. 我把字符串部分的都删除了吧,现在没有字符串的处理,主要就是 values 那个字典。
  3. 我觉得还是不要修改他的数据结构了,尽量和原作者的文档保持一致。但是可以新增几个更加 readable 的 API。修改代码有一定难度,现在也没有写测试,我感觉会容易出错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants