clpfd Questions
5
Solved
What is the best way to convert binary bits (it might be a list of 0/1, for example) into numbers in a reversible way. I've written a native predicate in swi, but is there better solution ?
Best re...
6
I am beginner in Prolog programming.
I wrote this program to calculate the length of a list. Why is below program wrong?
length(0, []).
length(L+l, H|T) :- length(L, T).
I wrote below program an...
4
My professor gave this as an example of Prolog. It is a program that solves the Tower of Hanoi puzzle, where you have to move a stack of disks to another peg by moving one disk after the other, wit...
Coy asked 28/5, 2016 at 13:17
4
I came across this natural number evaluation of logical numbers in a tutorial and it's been giving me some headache:
natural_number(0).
natural_number(s(N)) :- natural_number(N).
The rule roughl...
Bicker asked 21/1, 2012 at 16:6
3
Solved
I saw this ECLiPSe solution to the problem mentioned in this XKCD comic. I tried to convert this to pure Prolog.
go:-
Total = 1505,
Prices = [215, 275, 335, 355, 420, 580],
length(Prices, N),
...
Tantalizing asked 6/6, 2011 at 14:28
2
CLPFD-systems are not primarily targeted to handle quadratic equations efficiently, nevertheless, are there better ways to formulate problems like the following?
It seems the problem boils down to...
2
I'm learning Prolog by doing the Advent of Code challenges.
Spoilers for Advent of Code 2021 day 7 below:
The objective is: given a list of natural numbers n_1,..., n_k, find
min_(x\in \N) \sum_i=0...
Philharmonic asked 7/12, 2021 at 21:39
2
Solved
I try to implement efficient exclusive-or (XOR) in Prolog CLPFD. This should be simple predicate like:
xor(A, B, AxorB).
A, B, AxorB are natural numbers (with 0) and AxorB is a result of A xor B...
Institutionalism asked 17/5, 2014 at 21:39
2
Solved
Question: Fill in the grid with squares (of any size) that do not touch or overlap, even at the corners. The numbers below and at the
right indicate the number of grid squares that are filled in t...
Orcinol asked 29/12, 2020 at 19:29
2
Solved
How to convert float to integer in prolog?
I tried:
?- integer(truncate(sqrt(9))).
false.
?- integer(round(sqrt(9))).
false.
Crook asked 4/12, 2010 at 16:27
5
A strange question follows:
I'm doing a problem solving competition @ my school, and they allow us to use a computer. Since I'm the only one in the competition who knows how to code, I use C and Pa...
Rickard asked 29/3, 2013 at 14:13
5
Solved
I'm trying to solve a constraint processing problem in prolog.
I need to pack 4 squares of 5x5,4x4,3x3 and 2x2 in a grid of 10x10.
They may not overlap.
My variables look like this:
Name: SqX(i)...
Lifesaver asked 29/11, 2012 at 10:33
1
Solved
I could not find division (/) symbol on this page of CLP(FD): http://www.swi-prolog.org/man/clpfd.html
Also this simple code give error:
:-use_module(library(clpfd)).
afn(A,B,C):-
C #= B / A.
...
Paperboy asked 5/7, 2016 at 8:42
6
Solved
I'm trying to duplicate the behavior of the standard length/2 predicate. In particular, I want my predicate to work for bounded and unbounded arguments, like in the example below:
% Case 1
?- leng...
4
Solved
I have a program written in Sicstus Prolog using constraints.
My goal is to use labeling/2 and some other method to obtain a random instantiation of my variables.
Example:
X #> 2, Y #= 2*X, Z ...
Dzerzhinsk asked 1/1, 2012 at 15:23
1
Solved
Consider the problem from https://puzzling.stackexchange.com/questions/20238/explore-the-square-with-100-hops:
Given a grid of 10x10 squares, your task is to visit every square exactly once. In ...
9
Solved
The N-Queens Problem:
This problem states that given a chess board of size N by N, find the different permutations in which N queens can be placed on the board without any one threatening each ot...
4
I read a brief article about Prolog and Logic Programming. I'm curious if Logic Programs can do algebra. Like would you be able to ask what the Variable of X is in the equation 5+X = 7 and get an a...
Sumikosumma asked 3/12, 2012 at 19:19
2
Solved
I recently found a small game on the Google Play app store called Cryptogram. There are dozens of apps similar to this one. The idea is to match the number to the colors such that all of the equati...
Krefetz asked 15/4, 2018 at 4:9
1
Solved
I wrote a quick predicate in Prolog trying out CLP(FD) and its ability to solve systems of equations.
problem(A, B) :-
A-B #= 320,
A #= 21*B.
When I call it in SWI, I get:
?- problem(A,B).
32...
Sontag asked 26/12, 2017 at 6:24
1
Solved
I am writing a Prolog program using clp(fd) and am having difficultly implementing one of my desired constraints.
The output is a list of integers (the length is dependent on the input to another ...
6
I want to write a predicate that an integer and a list of digits, and succeed if Digits contain the digits of the integer in the proper order, i.e:
?-digit_lists( Num, [1,2,3,4] ).
[Num == 1234].
...
6
Solved
I'm trying to count the numer of inversions in a list. A predicate inversion(+L,-N) unifies N to the number of inversions in that list. A inversion is defined as X > Y and X appears before Y in ...
2
Solved
This question starts from Mat's answer to Algorithm improvement for enumerating binary trees which has only one input value that determines the number of all nodes for the binary tree, and the need...
Sabaean asked 8/3, 2017 at 13:22
3
Solved
I have written a CSP program using CLP(FD) and SWI-Prolog.
I think I need to improve my constraints' writing when I use the mod operator
together with #\/ in my predicates.
A short example :
:- ...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.