Skip to content

Instantly share code, notes, and snippets.

@bitoiu
Created January 15, 2014 17:14
Show Gist options
  • Save bitoiu/8440288 to your computer and use it in GitHub Desktop.
Save bitoiu/8440288 to your computer and use it in GitHub Desktop.
prolog permutations of 1 and 2 that add to 6
perm6([1],5).
perm6([2],4).
perm6([1|T], Current) :- Current < 6 , Next is Current +1, perm6(T, Next).
perm6([2|T], Current) :- Current < 6 , Next is Current +2, perm6(T, Next).
perm62(_, Current) :- Current >= 6, !.
perm62([1],5).
perm62([2],4).
perm62([1|T], Current) :- Next is Current +1, perm6(T, Next).
perm62([2|T], Current) :- Next is Current +2, perm6(T, Next).
perm6X(_, Current) :- Current >= 6, !.
perm6X([1],5).
perm6X([2],4).
perm6X([1|T], Current) :- Next is Current +1, perm6(T, Next).
perm6X([2|T], Current) :- Next is Current +2, perm6(T, Next).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment