Skip to content

Instantly share code, notes, and snippets.

@patrickbucher
Last active October 21, 2018 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickbucher/5eb6f1d39ce9002423f4fffa531b90cf to your computer and use it in GitHub Desktop.
Save patrickbucher/5eb6f1d39ce9002423f4fffa531b90cf to your computer and use it in GitHub Desktop.
Will Hamilton become World Champion in the 2018 US Grand Prix?
:- use_module(library(clpfd)).
points(1, 25).
points(2, 18).
points(3, 15).
points(4, 12).
points(5, 10).
points(6, 8).
points(7, 6).
points(8, 4).
points(9, 2).
points(10, 1).
current(hamilton, 331).
current(vettel, 264).
current(bottas, 207).
current(raikkoennen, 196).
driverchampion(Hamilton, Vettel) :-
Hamilton #\= Vettel,
H1 + H #> V1 + V + 75,
current(hamilton, H1),
current(vettel, V1),
points(Hamilton, H),
points(Vettel, V),
label([H, V, H1, V1]).
constructorchampion(Hamilton, Bottas, Vettel, Raikkoennen) :-
current(hamilton, H1),
current(bottas, B1),
current(vettel, V1),
current(raikkoennen, R1),
points(Hamilton, H),
points(Bottas, B),
points(Vettel, V),
points(Raikkoennen, R),
H + H1 + B + B1 #> V + V1 + R + R1 + 3 * (25 + 18),
all_distinct([Hamilton, Bottas, Vettel, Raikkoennen]),
label([H, H1, B, B1, V, V1, R, R1]).
@patrickbucher
Copy link
Author

Usage:

swipl formula1.pl
?- driverchamption(Hamilton, Vettel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment