/* Baseball coach dilemma in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" See https://www.researchgate.net/publication/374588335_Measuring_reasoning_capabilities_of_ChatGPT """ Puzzle 54. Baseball coach dilemma A baseball coach recalls that: 1. Charles played 5 more games than the player who wore number 28. 2. Jorge wore number 3. 3. Martin or who played shortstop, one wore number 21 and the other played 11 games. 4. Armando either wore number 32 or number 21. 5. Jorge either played 13 games or played first base. 6. The player who played 13 games didn't wear number 29. 7. Armando didn't play shortstop. 8. The right field player played 1 more game than the center field player. 9. Pedro played somewhat fewer games than Martin. 10. Neither Russell nor the player who played 13 games was number 21. 11. Benny didn't play second base. 12. Russell was either the boy who played right field or played 12 games. 13. Number 35 played somewhat fewer games than number 28. 14. Neither number 3 nor the player who played 13 games was Armando. 15. Number 29 was either the player who played 8 games or the person who played third base. 16. Armando didn't play 10 games. Could you help the coach to figure out the number of games played by each player, their numbers and positions? (taken from Math is fun—www.mathisfun.com) """ Unique solution: Name Position Number Games played -------------------------------------- Armando Second base 32 12 Benny Left field 7 13 Charles Shortstop 21 14 Jorge First base 3 10 Martin Third base 29 11 Pedro Center field 35 8 Russell Right field 28 9 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 7, Name = new_list(N), Name = 1..N, % Symmetry breaking, keep this constant Name = [Armando,Benny,Charles,Jorge,Martin,Pedro,Russell], NameS = ["Armando","Benny","Charles","Jorge","Martin","Pedro","Russell"], Place = new_list(N), Place :: 1..N, Place = [FirstBase,SecondBase,ThirdBase,Shortstop,_LeftField,RightField,CenterField], PlaceS = ["First base","Second base","Third base","Shortstop","Left field","Right field","Center field"], Number = new_list(N), Number :: 1..N, Number = [N3,_N7,N21,N28,N29,N32,N35], NumberS = [3,7,21,28,29,32,35], NumGames = new_list(N), NumGames :: 1..N, NumGames = [P8,_P9,P10,P11,P12,P13,_P14], NumGamesS = [8,9,10,11,12,13,14], all_different(Name), all_different(Place), all_different(Number), all_different(NumGames), % 1. Charles played 5 more games than the player who wore number 28. Charles #!= N28, % (N28 #= P8 #/\ Charles #= P13) #\/ (N28 #= P9 #/\ Charles #= P14), sum([N28 #= NumGames[I] #/\ Charles #= NumGames[I+5] : I in 1..N-1, I+5 <= N ]) #= 1, % 2. Jorge wore number 3. Jorge #= N3, % 3. Martin or who played shortstop, one wore number 21 and the other played 11 % games. Martin #!= Shortstop, (Martin #= N21 #/\ Shortstop #= P11) #\/ (Shortstop #= N21 #/\ Martin #= P11), % 4. Armando either wore number 32 or number 21. Armando #= N32 #\/ Armando #= 21, % 5. Jorge either played 13 games or played first base. Jorge #= P13 #\/ Jorge #= FirstBase, % 6. The player who played 13 games didn't wear number 29. P13 #!= N29, % 7. Armando didn't play shortstop. Armando #!= Shortstop, % 8. The right field player played 1 more game than the center field player. sum([CenterField #= NumGames[I] #/\ RightField #= NumGames[I+1] : I in 1..N-1 ]) #= 1, % 9. Pedro played somewhat fewer games than Martin. sum([Pedro #= NumGames[I] #/\ Martin #= NumGames[J] : I in 1..N-1, J in I+1..N ]) #= 1, % 10. Neither Russell nor the player who played 13 games was number 21. Russell #!= P13, Russell #!= N21, P13 #!= N21, % 11. Benny didn't play second base. Benny #!= SecondBase, % 12. Russell was either the boy who played right field or played 12 games. Russell #= RightField #\/ Russell #= P12, % 13. Number 35 played somewhat fewer games than number 28. N35 #!= N28, sum([N35 #= NumGames[I] #/\ N28 #= NumGames[J] : I in 1..N-1, J in I+1..N ]) #= 1, % 14. Neither number 3 nor the player who played 13 games was Armando. N3 #!= P13, N3 #!= Armando, Armando #!= P13, % 15. Number 29 was either the player who played 8 games or the person who played % third base. N29 #= P8 #\/ N29 #= ThirdBase, % 16. Armando didn't play 10 games. Armando #!= P10, % Could you help the coach to figure out the number of games played by each player, % their numbers and positions? (taken from Math is fun—www.mathisfun.com) Vars = [name=Name,place=Place,number=Number,numberGames=NumGames], solve($[ff,split],Vars), println("Name Position Number Games"), println(" played"), println("--------------------------------------"), foreach(I in 1..N) element(Nm,Name,I), element(P,Place,I), element(Nn,Number,I), element(NG,NumGames,I), printf("%-8s %-12s %2d %2d\n", NameS[Nm],PlaceS[P],NumberS[Nn],NumGamesS[NG]) end, fail, nl.