% % A program to solve the logic puzzle from % https://www.ahapuzzles.com/logic/zebra/upcoming-blues-band % (Aha!Puzzles by james@ahapuzzles.com) % Six musicians are engaged in a conversation about starting a blues % band. Which name was suggested by which musician? % % Author: Joachim Schimpf, 2024 % Creative Commons Attribution 4.0 International License. % % ?- go. % Yellow Dog : musician(victor, black, piano, 65y) % Indigo Swing : musician(yousef, purple, saxophone, 25y) % Texas Flood : musician(theodore, green, clarinet, 45y) % Voodoo Crew : musician(eugene, yellow, harmonica, 50y) % King Snake Shake : musician(kyle, white, guitar, 35y) % Electric Gumbo : musician(ian, pink, drums, 60y) % Yes (0.01s cpu, solution 1, maybe more) % No (0.03s cpu) % :- lib(ic_symbolic). :- lib(ic). :- import alldifferent/1, element/3, indomain/1 from ic_symbolic. :- local domain(shirt(black,green,pink,purple,white,yellow)), domain(name(eugene,ian,kyle,theodore,victor,yousef)), domain(instrument(clarinet,drums,guitar,harmonica,piano,saxophone)), domain(band('Electric Gumbo','Indigo Swing','King Snake Shake','Texas Flood','Voodoo Crew','Yellow Dog')), domain(age('25y','35y','45y','50y','60y','65y')). go :- N = 6, length(Shirt, N), Shirt &:: shirt, alldifferent(Shirt), length(Name, N), Name &:: name, alldifferent(Name), length(Inst, N), Inst &:: instrument, alldifferent(Inst), length(Band, N), Band &:: band, alldifferent(Band), length(Age, N), Age &:: age, alldifferent(Age), % The man in the Black shirt plays an instrument that has Keys. element(BlackPlayer, Shirt, black), element(BlackPlayer, Inst, piano), % The Saxophone player suggested the band name Indigo Swing. element(SaxPlayer, Inst, saxophone), element(SaxPlayer, Band, 'Indigo Swing'), % The musician named Ian suggested the band name Electric Gumbo. element(IanPlayer, Name, ian), element(IanPlayer, Band, 'Electric Gumbo'), % The 50-year-old man is exactly to the left of the % musician that suggested the band name King Snake Shake. element(Age50Player, Age, '50y'), Age50Player + 1 #= KSSPlayer, element(KSSPlayer, Band, 'King Snake Shake'), % The 25-year-old musician is seated next to the Clarinetist. element(Age25Player, Age, '25y'), element(ClarinetPlayer, Inst, clarinet), Age25Player - ClarinetPlayer #= +-1, % Yousef is seated somewhere between the man in the % Black shirt and Theodore, in that order. element(YousefPlayer, Name, yousef), element(TheodorePlayer, Name, theodore), BlackPlayer #< YousefPlayer, YousefPlayer #< TheodorePlayer, % The man in the White shirt is 35 years old. element(WhitePlayer, Shirt, white), element(WhitePlayer, Age, '35y'), % The musician in the Green shirt is exactly to the right % of the Saxophone player. element(GreenPlayer, Shirt, green), SaxPlayer + 1 #= GreenPlayer, % Victor is seated next to the youngest musician. element(VictorPlayer, Name, victor), Age25Player - VictorPlayer #= +-1, % Eugene is seated in the fourth position. element(4, Name, eugene), % The Drummer suggested the band name Electric Gumbo. element(DrumsPlayer, Inst, drums), element(DrumsPlayer, Band, 'Electric Gumbo'), % The Harmonica player is adjacently seated to the % musician who plays a String instrument. element(HarmPlayer, Inst, harmonica), element(GuitarPlayer, Inst, guitar), HarmPlayer - GuitarPlayer #= +-1, % Ian is wearing a Pink shirt. element(IanPlayer, Shirt, pink), % The 50-year-old musician is seated next to the man % whose instrument has to be plucked. Age50Player - GuitarPlayer #= +-1, % Kyle is seated next to the Drummer. element(KylePlayer, Name, kyle), KylePlayer - DrumsPlayer #= +-1, % The man in the Yellow shirt suggested the band name Voodoo Crew. element(YellowPlayer, Shirt, yellow), element(YellowPlayer, Band, 'Voodoo Crew'), % The 45-year-old musician is seated somewhere between % Yousef and the 35-year-old musician, in that order. element(Age45Player, Age, '45y'), element(Age35Player, Age, '35y'), YousefPlayer #< Age45Player, Age45Player #< Age35Player, % The 60-year-old man is wearing a Pink shirt. element(Age60Player, Age, '60y'), element(Age60Player, Shirt, pink), % The musician that suggested the band name Yellow Dog is the oldest. element(Age65Player, Age, '65y'), element(Age65Player, Band, 'Yellow Dog'), % The man in the Green shirt suggested the band name Texas Flood. element(GreenPlayer, Band, 'Texas Flood'), % Labeling ( foreach(Xs, [Shirt,Name,Inst,Band,Age]) >> foreach(X, Xs) do indomain(X) ), % Result ( foreach(S,Shirt), foreach(N,Name), foreach(I,Inst), foreach(B,Band), foreach(A,Age) do writeln(B:musician(N,S,I,A)) ).