0

I have this specific problem but i can't formulate in Prolog syntax. I am very new.

my finite domain : all 10-balls combinations from 70 balls

requested solution : 10-balls combinations

constraints : i have a list of 20 balls set : set1, set2 .. setN

selected combinations not member of all 10-balls combination of set1, set2 ... setn (combi of 10-balls from 20 balls)

Thank you for your help

false
  • 10,264
  • 13
  • 101
  • 209
Bodstwo
  • 1
  • 1
  • 1
    You can use `member` to check if a ball has already been added to your list of 10 balls, then add it in the next goal if it hasn't. Prolog's backtracking mechanism will try all possible combinations as solutions. – G_V Mar 28 '18 at 13:15
  • constraints is applied to all balls in a the wanted combination not to a single ball – Bodstwo Mar 28 '18 at 13:28
  • I have no idea what that means – G_V Mar 28 '18 at 14:28
  • instead of balls, take it as numbered balls or lottery balls. The target combination can't be member of all combi(10,set1), combi(10,set2)...combi(10,setn) – Bodstwo Mar 29 '18 at 09:53
  • Yes, each ball must be unique for each set, which is what `member` can do for you. In the same way you can write a predicate that checks for existence of a unique ball in all your previously found sets. That way you can draw 30 unique balls from say a set of 50, in groups of 5, by simply checking whether the ball has been drawn before. You could also just remove the ball from the list of options by rebuilding a list without the picked ball. – G_V Mar 29 '18 at 09:55
  • 1
    @G_V Could you check my new answer ? – Bodstwo Jul 24 '18 at 15:58

1 Answers1

0

This is my solution to the question.

I don't know if it is optimal.

i am running the code on VPS with 3000 intersections. (below a part of the code only 7 sets intersections)

I don't know if PROLOG able to solve it ?

%use_module(library(clpfd)).


solve_frkeno(B1,B2,B3,B4,B5,B6,B7,B8,B9,B10) :-

     between(1, 13, B1),
     between(4, 21, B2),
     between(8, 29, B3),
     between(14, 37, B4),
     between(18, 41, B5),
     between(27, 50, B6),
     between(35, 57, B7),
     between(42, 63, B8),
     between(50, 68, B9),
     between(58, 70, B10),

     all_different([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10]),

    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[5,6,13,16,19,20,22,30,31,34,35,39,40,51,52,56,59,61,65,69],I1),
    length(I1,N1),
    between(0,6,N1),
    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[5,8,9,13,14,16,21,24,29,33,35,47,49,52,54,58,59,64,65,68],I2),
    length(I2,N2),
    between(0,6,N2),
    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[1,3,6,12,16,21,23,25,28,37,39,40,42,44,48,49,50,58,63,69],I3),
    length(I3,N3),
    between(0,6,N3),
    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[4,8,9,14,21,24,26,28,36,45,46,52,54,57,59,60,61,62,63,67],I4),
    length(I4,N4),
    between(0,6,N4),
    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[9,11,13,16,19,20,25,27,28,29,34,39,41,48,49,50,53,63,64,65],I5),
    length(I5,N5),
    between(0,6,N5),
    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[4,5,9,12,19,29,30,32,33,34,35,38,42,45,49,57,58,60,62,70],I6),
    length(I6,N6),
    between(0,6,N6),
    intersection([B1,B2,B3,B4,B5,B6,B7,B8,B9,B10],[2,3,6,12,13,15,16,19,26,29,30,40,43,51,52,53,58,64,67,69],I7),
    length(I7,N7),
    between(0,6,N7),
Bodstwo
  • 1
  • 1