0

PROLOG newbie here. I have the following list:

list([im204, im209, im210, im212, im214, im216, im217, im218]).

I need a schedule(A,B,C) predicate which will return all possible combinations/divsions of the elements above in three subsets A, B, C.

i.e:

?- schedule(A,B,C). 
A = [im204,im209,im210], 
B = [im212,im214,im216], 
C = [im217,im218] ; 
A = [im204,im209,im210], 
B = [im212,im214,im216], 
C = [im218,im217] ;
(...)

Can someone show me a simple implementation?

false
  • 10,264
  • 13
  • 101
  • 209
athageor
  • 31
  • 1
  • vote to reopen: not a double. the OP describes a partition of a list into 3 subsets of almost-same length, not the powerset as in the linked Q. @lurker – Will Ness Jun 07 '18 at 10:22
  • @WillNess I reopened because it is not simply a subset problem. But it is probably a duplicate of [Partition a set into n subsets using Prolog](https://stackoverflow.com/questions/48213714/partition-a-set-into-n-subsets-using-prolog). If I were able to re-vote to close, I would probably do so on that basis. – lurker Jun 07 '18 at 11:10
  • @lurker ah, this is closer, though still not quite the dupe: our subsets must all be of the same length (except for the last one). that's how I interpret the Q. or maybe it's not so... yes, I think I was mistaken there. – Will Ness Jun 07 '18 at 11:13
  • 1
    Possible duplicate of [partition a set into n subsets using prolog](https://stackoverflow.com/questions/48213714/partition-a-set-into-n-subsets-using-prolog) – Will Ness Jun 07 '18 at 11:15
  • @athageor either it is a duplicate, or the question is unclear. please clarify. – Will Ness Jun 07 '18 at 11:16
  • @WillNess yes, you're right. Probably a simple variant. – lurker Jun 07 '18 at 11:17
  • 1
    @lurker I changed your mind, by in the mean time, I changed mine. :) the Q is really unclear there. – Will Ness Jun 07 '18 at 11:17
  • 1
    I meant to say, but in the mean time you changed mine. @ lurker – Will Ness Jun 07 '18 at 13:08

0 Answers0