Skip to content

Instantly share code, notes, and snippets.

@cmungall
Created February 18, 2019 23:56
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 cmungall/5e9d912512dabfb22c2420eebda408fb to your computer and use it in GitHub Desktop.
Save cmungall/5e9d912512dabfb22c2420eebda408fb to your computer and use it in GitHub Desktop.
% from https://twitter.com/mbeisen/status/1097569638555086851
:- use_module(library(clpfd)).
% xi where 1 <= xi <= M, 1 <= i <= N, sum(xi = 2M)
solve(M,N,L) :- length(L,N), L ins 1..M, sum(L,#=,M*2).
% use random_variable option when labeling results
test(M,N) :-solve(M,N,L), labeling([random_variable(5)],L), writeln(L), fail ; halt.
% TO RUN
% first install SWI-Prolog7 or higher
% on command line:
swipl -l clpdf_example.pl -g "test(8,12)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment