Created
February 18, 2019 23:56
-
-
Save cmungall/5e9d912512dabfb22c2420eebda408fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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