clpfd

About building a list until it meets conditions

Deadly 提交于 2021-01-27 06:13:06
问题 I wanted to solve "the giant cat army riddle" by Dan Finkel using Prolog. Basically you start with [0] , then you build this list by using one of three operations: adding 5 , adding 7 , or taking sqrt . You successfully complete the game when you have managed to build a list such that 2 , 10 and 14 appear on the list, in that order, and there can be other numbers between them. The rules also require that all the elements are distinct, they're all <=60 and are all only integers. For example,

About building a list until it meets conditions

非 Y 不嫁゛ 提交于 2021-01-27 06:12:29
问题 I wanted to solve "the giant cat army riddle" by Dan Finkel using Prolog. Basically you start with [0] , then you build this list by using one of three operations: adding 5 , adding 7 , or taking sqrt . You successfully complete the game when you have managed to build a list such that 2 , 10 and 14 appear on the list, in that order, and there can be other numbers between them. The rules also require that all the elements are distinct, they're all <=60 and are all only integers. For example,

convert float to integer in prolog

走远了吗. 提交于 2020-06-25 00:58:27
问题 How to convert float to integer in prolog? I tried: ?- integer(truncate(sqrt(9))). false. ?- integer(round(sqrt(9))). false. 回答1: The predicate integer/1 that you used is true iff its argument is an integer. Since the term truncate(sqrt(9)) is not an integer, the predicate does not hold and therefore fails for this term. There are at least two ways to get what you want: Solution 1: Quick and broken You can use the predicate (is)/2 for conversion between different number representations. In

Prolog - Calculating coordinates of Koch-curve

半城伤御伤魂 提交于 2020-01-15 06:16:26
问题 I'm learning about constraint programming and recursive programming in Prolog. I have to programm a koch-curve of Level N which should start at (Sx,Sy) and end at (Ex,Ey) .The line-segments, which are being calculated, will be stored in Ls. When I try to execute generatelines(1,(60,0),(-60,0),Ls) , I get the right 4 coordinates of the koch-curve of level 1: [[ (60, 0), (20, 0)], [ (20, 0), (0.0, -34.64)], [ (0.0, -34.64), (-20, 0)], [ (-20, 0), (-60, 0)]] When I try to execute generatelines(2

Reversible tree length relation

点点圈 提交于 2020-01-11 05:25:14
问题 I'm trying to write reversible relations in "pure" Prolog (no is , cut, or similar stuff. Yes it's homework), and I must admit I don't have a clue how. I don't see any process to create such a thing. We are given "unpure" but reversible arithmetic relations (add,mult,equal,less,...) which we must use to create those relations. Right now I'm trying to understand how to create reversible functions by creating the relation tree(List,Tree) which is true if List is the list of the leaves of the

Example channelling constraints ECLiPSe

情到浓时终转凉″ 提交于 2020-01-11 01:41:17
问题 Can someone provide a simple example of channelling constraints? Channelling constraints are used to combine viewpoints of a constraint problem. Handbook of Constraint Programming gives a good explanation of how it works and why it can be useful: The search variables can be the variables of one of the viewpoints, say X1 (this is discussed further below). As search proceeds, propagating the constraints C1 removes values from the domains of the variables in X1. The channelling constraints may

Why doesn't this clpfd query terminate until I add a redundant constraint?

假装没事ソ 提交于 2020-01-04 04:13:05
问题 I've written some predicates which take the length of a list and attaches some constraints to it (is this the right vocabulary to be using?): clp_length([], 0). clp_length([_Head|Rest], Length) :- Length #>= 0, Length #= Length1 + 1, clp_length(Rest, Length1). clp_length2([], 0). clp_length2([_Head|Rest], Length) :- Length #= Length1 + 1, clp_length2(Rest, Length1). The first terminates on this simple query, but the second doesn't: ?- Small in 1..2, clp_length(Little, Small). Small = 1,

How to trace backtracks of clpfd in prolog?

自闭症网瘾萝莉.ら 提交于 2020-01-04 02:22:08
问题 I am making a sudoku solver with prolog using clpfd library . I have to trace the backtracks and every squares labeled with row and column and the number it gets in the following form: (1 ,1 ,1) (9 ,2 ,1) BT (5 ,2 ,1) My question is how can I get the above information from the algorithm? Another question: Does the algorithm observe arc-consistency rules by itself? 回答1: I don't think this is a particularly good idea, but here is something using SWI-Prolog's attributed variables that prints the