简体   繁体   English

解决Prolog中的逻辑难题(黑毛,黑细胞在哪里)

[英]Solving a logic puzzle (Kuromasu, Where is black cells) in Prolog

I have some problems with solving puzzle. 我在解决难题时遇到了一些问题。 I haven't found solution for this puzzle anywhere, but I tried to write it in Prolog, but I think my solution won't be fast (I generate every solution and delete them if they aren't possible or correct). 我在任何地方都没有找到解决这个难题的方法,但是我尝试用Prolog编写它,但是我认为我的解决方法不会很快(我将生成所有解决方案,如果不可能或不正确,则将其删除)。 This is my problem: (I found a name of that puzzle, here is the link with all rules of that puzzle: http://en.wikipedia.org/wiki/Kuromasu ). 这是我的问题:(我找到了该难题的名称,下面是该难题的所有规则的链接: http : //en.wikipedia.org/wiki/Kuromasu )。 Now I have a different question, which method would be the quite easy to write and quite fast to solve it in Prolog. 现在我有一个不同的问题,哪种方法在Prolog中将很容易编写并且可以很快地解决它。 I thought about transforming my list of fields into a undirected graph, or maybe there is another method to search my list vertically (head after head)? 我考虑过将字段列表转换为无向图,或者也许还有另一种方法可以垂直(头对头)搜索列表?

In: 在:

0, 0, 0, 5, 0, 0, 0
0, 5, 0, 0, 0, 0, 2
0, 0, 0, 0, 7, 0, 4
0, 0, 0, 0, 0, 0, 0
8, 0, 13,0, 0, 0, 0
5, 0, 0, 0, 0, 6, 0
0, 0, 0, 8, 0, 0, 0

Result: 结果:

0, #, 0, 5, 0, 0, #
0, 5, 0, 0, 0, #, 2
0, #, 0, #, 7, 0, 4
#, 0, 0, 0, 0, 0, #
8, 0, 13,0, 0, 0, 0
5, 0, 0, 0, #, 6, 0
#, 0, 0, 8, 0, 0, #

This type of puzzles is called Kuromasu. 这种难题被称为Kuromasu。 Here is a page that solves it with SWI-Prolog and finite domain constraints: http://jfoutelet.developpez.com/articles/kuromasu/ 这是一个使用SWI-Prolog和有限域约束来解决该问题的页面: http : //jfoutelet.developpez.com/articles/kuromasu/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM