/* Final student problem in Picat. From Chris Smith's MathNewsletter #555 """ Mrs Krabappel gave her class a test and she’s almost marked them all, just one to go If the final student scores just 7% then the class average will be 90% but, even more remarkably, if they score 92% then they’ll be looking at a class average of 95% (and Mrs K will be in line for a bonus). How many students are in the class? """ * The cp/sat model go/0 give: cp: n = 17 x = [96,96,96,95,95,95,95,95,95,95,95,95,95,95,95,95] sat: n = 17 x = [100,100,100,100,100,100,100,100,100,97,97,96,92,84,84,73] smt: n = 17 x = [100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,23] mip (cbc and glpk): n = 17 x = [100,100,100,100,100,100,100,100,100,100,100,100,100,100,62,61] * The mip model go_mip/0 (only for the mip solvers): glpk: n = 17 x = [100,100,100,100,100,100,100,100,100,100,100,100,100,100,23,100] cbc give a strange solution: n = 3 x = [100,163] Note: The MiniZinc model final_student.mzn give this solution (using OptiMathSAT): n: 17 x: [100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 22.99999999999994] This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. % import cp. % import sat. % import smt. main => go. % % cp/sat % go ?=> nolog, member(N, 2..100), println(n=N), X = new_list(N-1), X :: 0..100, decreasing(X), % (sum(X[1..N-1]) + 7) / N #= 90, % (sum(X[1..N-1]) + 92) / N #= 95, % Move division to RHS (sum(X[1..N-1]) + 7) #= 90*N, (sum(X[1..N-1]) + 92) #= 95*N, solve($[ff,split,limit(3)],X), println(n=N), println(x=X), nl, fail, nl. go => true. % % Test of MIP solver % go2 ?=> nolog, N = 18, println(n=N), X = new_list(N-1), X :: 0..100, decreasing(X), % (sum(X[1..N-1]) + 7) / N #= 90, % (sum(X[1..N-1]) + 92) / N #= 95, % Move division to RHS (sum(X[1..N-1]) + 7) #= 90*N, (sum(X[1..N-1]) + 92) #= 95*N, solve($[ff,split,limit(3)],X), println(n=N), println(x=X), nl, fail, nl. go2 => true. % % For MIP solver. % go_mip ?=> member(N, 2..100), println(n=N), X = new_list(N-1), X :: 0.0..100.0, % decreasing(X), % (sum(X[1..N-1]) + 7) / N #= 90, % (sum(X[1..N-1]) + 92) /N #= 95, % Move division to RHS (sum(X[1..N-1]) + 7.0) #= 90.0*N, (sum(X[1..N-1]) + 92.0) #= 95.0*N, solve($[],X), println(n=N), println(x=X), nl, % fail, nl. go_mip => true.