Imperative (not functional) languages are so boring. Long life to logical and declarative programming like Prolog


Below a simple example of using a a declarative language (Prolog) for finding all solutions for a trick game…

?- use_module(library(clpfd)).
?- X in 1..9, Y #= (X * 3 + 3) * 3, Z #= (Y rem 10) + (Y div 10), setof(Z, X^Y^label([X,Y,Z]), Sol).

Sol = [9],

Enter your instance's address

More posts like this

Smart investment Problem with Prolog

2024-07-14 | #programming #prolog

Below my #prolog solution for Smart investment problem. It is a sample of Linear Programming using Prolog. A client of an investment firm has $10000 available for investment. He has instructed that his money be invested in particular stocks, so that no more than $5000 is invested in any one stock but at least $1000 be invested in each stock.

Continue reading 

Stable Marriage Problem with Prolog

2024-06-07 | #programming #prolog

My #prolog solution for Stable Marriage Problem proposed by challenge Jun 2024. Given n men and n women, where each person has ranked all members of the opposite sex in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners.

Continue reading 