/* People in a room problem in Picat. https://groups.google.com/forum/#!topic/alt.sci.math.combinatorics/noYJ8odV6Ss """ There are 20 people. 6 of them are male. They randomly enter a room one at a time. In how many ways can the males and females enter so that the ratio of females to males in the room at any one time is no greater than 7/3? """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import cp. main => go. go => N = 20, NumMale = 6, NumFemale = N-NumMale, FemaleC = 7, MaleC = 3, time2(people_in_a_room(N,NumMale,NumFemale,MaleC,FemaleC, All)), All2 = [[cond(A[I] = 1,"M","F") : I in 1..N].join('') : A in All].join('\n'), println(All2), println(len=All.length), nl. people_in_a_room(N,NumMale,NumFemale,MaleC,FemaleC, All) => Male = 1, Female = 2, % decision variables X = new_list(N), X :: Male..Female, global_cardinality(X, $[Male-NumMale,Female-NumFemale]), % The ratio of females / males in any time must not be >= 7/3 (FemaleC / MaleC) foreach(I in 1..N) MaleC *sum([X[J]#=Female : J in 1..I]) #<= sum([X[J]#=Male : J in 1..I]) * FemaleC end, All = solve_all([ffd,split],X).