PROLOG中的填字游戏求解器 [英] Crossword solver in PROLOG

查看:250
本文介绍了PROLOG中的填字游戏求解器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

天堂岛的克里奥尔语有14个单词:放弃",鲍鱼",字谜",船",船夫",孩子",连接",优雅",增强",岛" ",男人",沙子",太阳"和女人".

The creole of Paradise Island has 14 words: "abandon", "abalone", "anagram", "boat", "boatman", "child", "connect", "elegant", "enhance", "island", "man", "sand", "sun", and "woman".

《天堂时报》有 发布了这个填字游戏:

The Paradise Times have published this crossword:

填字游戏包含14个单词中的一些,但没有其他单词.

The crossword contains some of the 14 words but no other words.

写 始于

Write a Prolog program that starts from

word(X) :-
member(X,
[
[a,b,a,n,d,o,n], [a,b,a,l,o,n,e], [a,n,a,g,r,a,m],
[b,o,a,t], [b,o,a,t,m,a,n], [c,h,i,l,d],
[c,o,n,n,e,c,t], [e,l,e,g,a,n,t], [e,n,h,a,n,c,e],
[i,s,l,a,n,d], [m, a, n], [s,a,n,d],
[s,u,n], [w, o, m, a, n]
]).

solution(H1,H2,H3,V1,V2,V3) :-

并以这样的方式定义谓词solution

and defines the predicate solution in such a way that

solution(H1,H2,H3,V1,V2,V3)

当且仅当H1H2H3V1V2V3是天堂的有效词时,

为true 写入上面给出的网格时形成有效填字游戏的岛. (例如,H1的第二个字母应与第二个字母重合 的V1.)

is true if and only if H1, H2, H3, V1, V2, and V3 are valid words of Paradise Island which form a valid crossword when written into the grid given above. (For example, the second letter of H1 should coincide with the second letter of V1.)

使用查询

?- solution(H1,H2,H3,V1,V2,V3).

解决填字游戏.找到所有填字游戏的解决方案.

to solve the crossword. Find all solutions to the crossword.

提示:您可能想从一个较小的填字游戏和一个不太丰富的填字游戏开始 词典.

Hint: You might want to start from a smaller crossword and a less rich lexicon.

推荐答案

只看图片,单词是用字母写的,图片中有一切,用Prolog行翻译(我的解决方案有12行,2行)一个词).

Just look at the picture, words are written with letters, you have everything in the picture, translaste it in Prolog lines (my solution has 12 lines, 2 lines for one word).

每个人都给出自己的解决方案,这是我的:

As every body gives its own solution, here is mine :

solution(H1,H2,H3,V1,V2,V3) :-
    H1 = [_,A2,_,A4,_,A6,_],
    H2 = [_,B2,_,B4,_,B6,_],
    H3 = [_,C2,_,C4,_,C6,_],
    V1 = [_,A2,_,B2,_,C2,_],
    V2 = [_,A4,_,B4,_,C4,_],
    V3 = [_,A6,_,B6,_,C6,_],
    maplist(word, [H1,H2,H3,V1,V2,V3]).

我最初是PS 写词(H1), word(H2)...

PS I originally wrote word(H1), word(H2) ...

这篇关于PROLOG中的填字游戏求解器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆