/* 50 question puzzle (Le Monde puzzle #952) in Picat. From http://www.r-bloggers.com/le-monde-puzzle-952/ """ In a multiple choice questionnaire with 50 questions, Alice gets a score s such that Bob can guess how many correct (+5 points), incorrect (-1 point) and missing (0 point) Alice got when adding that Alice could not have gotten s-2 or s+2. What is Alice’s score? """ The answer: """ A first point is that the overall score is s=5c-i with c+i≤50. Without further information, the possible results are all integers 0≤c≤50 such that c≥s/5 and 0≤i=s-5c≤50. Possible scores range from -50 to 250, but a quick R check shows that ten values are impossible vales=rep(0,le=50+1+250) for (c in 0:50){ for (i in 0:(50-c))vales[5*c-i+50+1]=1} which produces > (1:length(vales))[vales==0]-50-1 [1] 231 236 237 241 242 243 246 247 248 249 Thus looking at the differences, there is only one case for which s-2 and s+2 are impossible values, namely s=239. This means c=48, i=1 since c=49 leads to an impossible i. """ I don't understand this, since This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => % garbage_collect(300_000_000), None = [], % The impossible scores: [231,236,237,241,242,243,246,247,248,249] Scores = [], % The possible scores foreach(Score in -50..5*50) if score(_X, Score) then Scores := Scores ++ [Score] else None := None ++ [Score] end end, % println(none=None), foreach(Score in min(None)..max(None), member(Score, Scores)) % 1) Score-2 and Score+2 must be impossible % 2) The score list must include all three values: -1, 0, and 5 so they can be identified. if member(Score-2, None), member(Score+2, None), score(X, Score), member(-1, X), member(0,X) then println(alice=Score) end end, nl. score(X, S) => N = 50, X = new_list(N), X :: [-1,0,5], S #= sum(X), S :: -N..N*5, solve($[],X).