Skip to content

Instantly share code, notes, and snippets.

View AndreFCruz's full-sized avatar
💻
Meeting deadlines

André Cruz AndreFCruz

💻
Meeting deadlines
View GitHub Profile
@AndreFCruz
AndreFCruz / colorir.pl
Last active January 7, 2018 18:42
Resolução do problema estendido de coloração de mapa com CLPFD.
%% P 7.3
% Versao estendida do problema de colorir um mapa.
% Para alem do problema original, apresenta restricoes de exclusao,
% condicoes positivas/negativas, diferencas e preferencias flexiveis.
:- use_module(library(lists)).
:- use_module(library(clpfd)).
%% Base de Factos
paises(5).
% Pergunta 3.3
:- use_module(library(lists)).
:- use_module(library(clpfd)).
objecto(piano, 3, 30).
objecto(cadeira, 1, 10).
objecto(cama, 3, 15).
objecto(mesa, 2, 15).
homens(4).
@AndreFCruz
AndreFCruz / p9_automaton.pl
Created January 7, 2018 22:32
Constraint logic programming problem.
%% P9
:- use_module(library(lists)).
:- use_module(library(clpfd)).
% numPecas(Id, Min, Max)
numPecas(1, 5, 15).
numPecas(2, 2, 6).
numPecas(3, 5, 10).
numPecas(4, 7, 12).
@AndreFCruz
AndreFCruz / p7.2.pl
Last active January 8, 2018 14:24
Constraint logic programming exercise.
%% P 7.2
:- use_module(library(lists)).
:- use_module(library(clpfd)).
% docente(Nome, Sexo, Start, End) -> pode dar aulas que comecem de Start a End
docente(pedro, m, 3, 6).
docente(joana, f, 3, 4).
docente(ana, f, 2, 5).
docente(joao, m, 2, 4).
@AndreFCruz
AndreFCruz / p13.pl
Created January 8, 2018 14:27
Constraint logic programming exercise.
:- use_module(library(lists)).
:- use_module(library(clpfd)).
%% P13 - Prova modelo algures no grupo do fb
% attend(+, -, -)
attend(FilmList, Goings, Worth) :-
length(FilmList, N),
length(Goings, N),
domain(Goings, 0, 1),
@AndreFCruz
AndreFCruz / p4.pl
Created January 8, 2018 14:31
Constraint logic programming exercise.
:- use_module(library(lists)).
:- use_module(library(clpfd)).
% P 4.a)
table6(L) :-
%% Indices in list L
% Asdrubal=1, Bernardete=2, Cristalinda=3
% Demetrio=4, Eleuterio=5, Felismina=6
L = [Asdr, Bern, Crist, Demet, Eleut, Felism],
domain(L, 1, 6),
@AndreFCruz
AndreFCruz / concelhos.pl
Created January 8, 2018 14:49
Constraint Logic Programming Exercise.
%% Exame PLOG 15-16
%% P13
:- use_module(library(lists)).
:- use_module(library(clpfd)).
% concelho(Nome, Distancia, NEleitoresIndecisos)
concelho(x, 120, 410).
concelho(y, 10, 800).
concelho(z, 543, 2387).
@AndreFCruz
AndreFCruz / magic_squares.pl
Last active January 19, 2018 15:48
Solving the Magic Squares with constraint logic programming. Examples in prolog and python.
% Solving Magic Squares using Sicstus PROLOG
:- use_module(library(clpfd)).
:- use_module(library(lists)).
matrixDomain([], _).
matrixDomain([Row | Matrix], N) :-
NSquared is N * N,
length(Row, N),
domain(Row, 1, NSquared),
@AndreFCruz
AndreFCruz / magic_squares.py
Created March 3, 2018 17:13
Solving the Magic Squares problem using constraint programming with Google's ortools.
# Solving Magic Squares using Google's ortools
# https://github.com/google/or-tools
from ortools.constraint_solver import pywrapcp
import sys
def main(n=4):
# Create the solver.
solver = pywrapcp.Solver('Magic square')
# declare variables
@AndreFCruz
AndreFCruz / minimax.pl
Last active September 16, 2019 00:56
Prolog implementation of TicTacToe with MiniMax.
%% Code from http://www.emse.fr/~picard/cours/ai/minimax/#sec-3
% minimax(Pos, BestNextPos, Val)
% Pos is a position, Val is its minimax value.
% Best move from Pos leads to position BestNextPos.
minimax(Pos, BestNextPos, Val) :- % Pos has successors
bagof(NextPos, move(Pos, NextPos), NextPosList),
best(NextPosList, BestNextPos, Val), !.
minimax(Pos, _, Val) :- % Pos has no successors