结束视图拼图,Prolog [英] End View Puzzle, Prolog

查看:192
本文介绍了结束视图拼图,Prolog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为End View Puzzles编写一个求解器,使用CLPFD(对于不熟悉的人,这里有一个简单的描述 http://www.funwithpuzzles.com/2009/12/abcd-end-view-a1.html )。我正在处理约束,我将应用于每一行/列,并遇到一些麻烦。

I'm trying to write a solver for End View Puzzles, using CLPFD (for those who are unfamiliar, here's a simple description http://www.funwithpuzzles.com/2009/12/abcd-end-view-a1.html ). I'm working on the constraint that I'll apply to each row/column, and running into some trouble.

所以我认为它应该看起来像这样:

So I'm thinking it should look something like this:

% NxN board, numbers from 0 to M in the row, Left/Right are the clues
% corresponding to the row
endviews(N,M,List,Left,Right):- 
    length(List,M),
    domain(List,0,M),
    stop_repeats(List,M),
    left_value(List,M,Left),
    reverse(List,RList),
    left_value(RList,M,Right)
    .

所以前三个步骤非常简单:初始化板,设置域,该行不会重复除 0 (我写了 stop_repeats / 2 谓词)之外的数字。我遇到的问题是处理 left_value / 3 谓词;我不太确定如何在这里继续,因为大多数列表不受约束,我实际上不知道这个第一个积极因素的位置。
任何帮助将非常感谢!

So the first 3 steps are pretty straight forward: initialize the board, set a domain, and make sure that this row won't repeat numbers other than 0 (I've written the stop_repeats/2 predicate). The problem I'm encountering is dealing with the left_value/3 predicate; I'm not really sure how to proceed here, since most of the list is not constrained and I do not actually know the position of this first positive element. Any help would be greatly appreciated!

推荐答案

也许 automaton / 3 约束可以帮助这里?您可以构造一个有限自动机,接受(可选)零后跟指定的第一个字母,然后是任意序列的零和字母。

Maybe the automaton/3 constraint can help here? You can construct a finite automaton that accepts (optional) zero followed by the first letter as indicated, then an arbitrary sequence of zero and letters.

这篇关于结束视图拼图,Prolog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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