/* Archery Match (Dudeney) in Picat. """ On a target on which the scoring was 40 for the bullseye, and 39, 24, 23, 17, and 16, respectively, for the rings from the centre outwards, as shown in the illustration, three players had a match with six arrows each. The result was: - Miss Dora Talbot, 120 points; - Reggie Watson, 110 points; - Mrs. Finch, 100 points. Every arrow scored, and the bullseye was only once hit. Can you, from these facts, determine the exact six hits made by each competitor? """ This is puzzle #467 from Dudeney's "536 Puzzles and Curious Problems". Cf archery_puzzle.pi This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> Names = ["Miss Dora Talbot", "Reggie Watson", "Mrs. Finch"], NumPeople = 3, L = [16,17,23,24,39,40], N = L.len, NumHits = 6, % 6 hits each Scores = [120,110,100], X = new_array(NumPeople,N), X :: 0..NumHits, % Every arrow scored, foreach(I in 1..NumPeople) sum(X[I]) #= NumHits, sum([X[I,J]*L[J] : J in 1..NumHits]) #= Scores[I] end, % and the bullseye was only once hit sum([X[I,N] #> 0 : I in 1..NumPeople]) #= 1, solve(X), foreach(I in 1..NumPeople) Sum = sum([X[I,J]*L[J] : J in 1..NumHits]), printf("%s (sum %d):\n", Names[I], Sum), foreach(J in 1..N) if X[I,J] > 0 then printf("\t%d x %d\n", L[J], X[I,J]) end end, nl end, fail, nl. go => true.