Riddle challenge lazarus / 8-Other ---------------------------------------------------------------------- Joanna · 2025-02-02 23:30 Here is a riddle to solve for fun.Quote There are five houses. The Englishman lives in the red house. The Spaniard owns the dog. Coffee is drunk in the green house. The Ukrainian drinks tea. The green house is immediately to the right of the ivory house. The Old Gold smoker owns snails. Kools are smoked in the yellow house. Milk is drunk in the middle house. The Norwegian lives in the first house. The man who smokes Chesterfields lives in the house next to the man with the fox. Kools are smoked in the house next to the house where the horse is kept. The Lucky Strike smoker drinks orange juice. The Japanese smokes Parliaments. The Norwegian lives next to the blue house. who drinks water? Who owns the zebra?If you succeed in solving on your own, please explain how you solved it. ---------------------------------------------------------------------- dbannon · 2025-02-03 13:04 You sure there is a solution ? Attached my attempt, Monte Carlo simulation, 10 Million runs and no successful candidate.  I may well have made a mistake, midnight here, I'll look in the morning. Its seriously rough work, only started when the TV got boring. But you can see the idea. Generate a random model, test it, repeat.... Davo ---------------------------------------------------------------------- MarkMLl · 2025-02-03 13:14 I've solved things like this in the past using Prolog, but right now can't afford the time to get "back into the mood". However I don't believe that that is soluble as it stands, since there are at least two facts missing, which I suggest tentatively are "every houseowner drinks something" and "every houseowner owns an animal": without those the questions relating to "water" and "a zebra" are meaningless. https://en.wikipedia.org/wiki/Zebra_Puzzle is relevant, and quotes the version of the puzzle given by Joanna as having the important rider QuoteIn the interest of clarity, it must be added that each of the five houses is painted a different color, and their inhabitants are of different national extractions, own different pets, drink different beverages and smoke different brands of American cigarets [sic]. One other thing: in statement 6, right means your right. Updated: https://www.literateprograms.org/zebra_puzzle__prolog_.html MarkMLl ---------------------------------------------------------------------- Joanna · 2025-02-03 13:21 I tried to work out the solution on paper first starting with the easiest ones which are first 3 houses. Listing known characteristics about each one from the list. I then got to the part  where there is an ivory color house to the left of the green house but I wasn’t sure if these were for house 3&4 or house 4&5 so I made two separate ones for both possibilities and continued adding by clues but then I got to another part where the clues could fit several different houses. It’s like the number of possibilities branch as you get into the puzzle and you need to try all possible answers to find out which one is correct. I solved the house colors , nationalities , beverages, cigarettes and didn’t quite solve the pets part. In general I think solving the clues with the most information first helps. ---------------------------------------------------------------------- 440bx · 2025-02-03 13:46 I've got half of it solved.  I know who drinks water.  That took about 10 minutes.  That was fairly easy. The second half looks pretty tough... (who owns the zebra), spent about another 10 minutes on that and didn't figure it out yet (and don't have much time to dedicate to it in the next few days.) @MarkMLI, I thought of Prolog too.  It's the perfect kind of problem for Prolog's goal seeking engine. ---------------------------------------------------------------------- MarkMLl · 2025-02-03 14:07 Quote from: 440bx on February 03, 2025, 02:46:45 pmI thought of Prolog too.  It's the perfect kind of problem for Prolog's goal seeking engine. Yes, but I've seen this type of puzzle equated to finding a path through a non-directed graph. The important point is that techniques have been developed over the last 60 years or so (i.e. since that specific puzzle was posed) to solve logical and- in the more general case- constraints-based problems efficiently: something that humans aren't all that good at since the vast majority of us lack the focus to tackle the problem methodically without getting sidetracked. MarkMLl ---------------------------------------------------------------------- Joanna · 2025-02-03 14:28 440bx what methodology did you use to solve it? It kind of reminds me of solving a sudoku puzzle... ---------------------------------------------------------------------- 440bx · 2025-02-03 15:48 Quote from: Joanna from IRC on February 03, 2025, 03:28:04 pm440bx what methodology did you use to solve it? It kind of reminds me of solving a sudoku puzzle... It does feel somewhat similar to sudoku. I made a 5x5 matrix and filled in the cells as I figured out what their value was based on the given constraints.  Currently I have slightly under 1/3 of the matrix filled (7 cells) which is enough to know who drinks water but, definitely not enough to figure out who owns the zebra.  I'm currently 18 cells short and I have a distinct feeling that many of the cells left require solving sets of constraints that involve relations among 4 or more constraints which is not very easy to visualize. Figuring out who drinks water was rather easy compared to figuring out who owns the zebra. ---------------------------------------------------------------------- LV · 2025-02-03 16:40 https://en.wikipedia.org/wiki/Zebra_Puzzle Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses  crt; type  THouse = record    Color: string;    Nationality: string;    Drink: string;    Smoke: string;    Pet: string;  end; const  HouseCount = 5; var  Houses: array[1..HouseCount] of THouse;  i: integer;  WaterDrinker, ZebraOwner: string; begin  clrscr;   { Manually assigning values based on logical deductions }  Houses[1].Color := 'Yellow';  Houses[1].Nationality := 'Norwegian';  Houses[1].Drink := 'Water';  Houses[1].Smoke := 'Kools';  Houses[1].Pet := 'Fox';  Houses[2].Color := 'Blue';  Houses[2].Nationality := 'Ukrainian';  Houses[2].Drink := 'Tea';  Houses[2].Smoke := 'Parliaments';  Houses[2].Pet := 'Horse';  Houses[3].Color := 'Red';  Houses[3].Nationality := 'Englishman';  Houses[3].Drink := 'Milk';  Houses[3].Smoke := 'Old Gold';  Houses[3].Pet := 'Snails';  Houses[4].Color := 'Ivory';  Houses[4].Nationality := 'Spaniard';  Houses[4].Drink := 'Orange Juice';  Houses[4].Smoke := 'Chesterfields';  Houses[4].Pet := '';  Houses[5].Color := 'Green';  Houses[5].Nationality := 'Japanese';  Houses[5].Drink := 'Coffee';  Houses[5].Smoke := 'Lucky Strike';  Houses[5].Pet := 'Zebra';   { Finding Water Drinker and Zebra Owner }  for i := 1 to HouseCount do  begin    if Houses[i].Drink = 'Water' then      WaterDrinker := Houses[i].Nationality;    if Houses[i].Pet = 'Zebra' then      ZebraOwner := Houses[i].Nationality;  end;   writeln('The person who drinks water is: ', WaterDrinker);  writeln('The person who owns the zebra is: ', ZebraOwner);   readln;end. ---------------------------------------------------------------------- 440bx · 2025-02-03 17:00 But, the real solution is to figure out all the necessary inferences that lead to the solution matrix they present. They give the half that's really easy (who drinks water.) They leave out all the inferences needed to fill the remaining 18 cells. ---------------------------------------------------------------------- LV · 2025-02-03 17:49 If you use translate.google, you can read the solution at the link https://ru.wikipedia.org/wiki/Загадка_Эйнштейна ---------------------------------------------------------------------- 440bx · 2025-02-03 18:46 Quote from: LV on February 03, 2025, 06:49:18 pmIf you use translate.google, you can read the solution at the link https://ru.wikipedia.org/wiki/Загадка_Эйнштейна Thank you for that but, first I want to try to figure out myself ---------------------------------------------------------------------- MathMan · 2025-02-03 23:04 Thanks for that Joanna, I went with human intelligence, Excell and manual backtracking. There were two decisions I had to make - positioning the red house <= two choices - positioning the Ukrainian <= two choices again Took me around 30min to solve -  if I hadn't missed a slot in the second decision I made I would have been there after ~15min. Anyway - one could also solve this via SAT solver - but setting up the equivalent boolean equations would probably have taken more time than the direct approach. Cheers, MathMan ---------------------------------------------------------------------- MathMan · 2025-02-03 23:18 Quote from: LV on February 03, 2025, 05:40:01 pmhttps://en.wikipedia.org/wiki/Zebra_Puzzle ... There is an error in the initial assignments in the program - look at the Japanese sharply. However - the deducted water drinker & zebra owner are correct. ---------------------------------------------------------------------- speter · 2025-02-04 00:27 I worked out a solution; the Norwegian drinks water and the Japanese has the zebra. I put the 'facts' into a grid (5x5 as MarkMLI did) and added all the other facts that were ambiguous. I then tried 6 permutations until I resolved the options into a single set of 'answers'. Have a look at the attached spreadsheet, if you want to check out my process. I haven't checked the webpage with the solution, so my "answer" could be wrong. cheers S. ---------------------------------------------------------------------- LV · 2025-02-04 06:20 With 5 attributes, each having 5! permutations, that's (5!)^5 = 24^5 = 7962624 possible combinations—about 8 million. Yes, the problem can be solved in a few steps with human intelligence and a bit of patience. Thank you, Joanna. I’m now taking the subway to work while solving riddles on my smartphone. ---------------------------------------------------------------------- Joanna · 2025-02-04 08:17 Good news I solved it.  What I did was made some rectangles of paper with the clues written on them then I taped the matching clues together and arranged the papers in order and continued taping the ones I was sure about together. There was some confusion whether the ivory and green houses should be 3&4 or 4&5 but then I noticed that the red house for Englishman had to be the 3rd house because there was no other place for it. After that I continued using clues and process of elimination to complete the rest of it. That was pretty fun ---------------------------------------------------------------------- dbannon · 2025-02-04 12:10 Gee, thought someone here would try for a FPC version ? Here is mine, slow, difficult to read, fun to write. Thanks Joanna Davo ---------------------------------------------------------------------- Thaddy · 2025-02-04 12:12 Let me give it a try with my fiveway logic and sets. Report later if it makes sense. My gut feeling is that sets removes at least the permutations squared part. ---------------------------------------------------------------------- Joanna · 2025-02-04 14:41 Quote from: dbannon on February 04, 2025, 01:10:14 pmGee, thought someone here would try for a FPC version ? Here is mine, slow, difficult to read, fun to write. Thanks Joanna Davo I wasn’t really planning to make code but regardless I think it’s a good idea to solve it manually to really understand it. The first 3 houses were the easiest to start with and the ivory and green house being adjacent . The Englishman living in red house eliminated all other houses with known colors or nationalities. So it could only go in center.  After that the puzzle was much easier than I had expected. The order in which the clues can be used is not immediately obvious. When I first tried to solve it I was not using the clues properly and I thought that I would have to try many different layouts. The pieces of paper made it a lot easier to see what was happening. I had to cycle through the clues to find the one that wasn’t ambiguous. So maybe the clue records would need a counter to check for multiple possibilities and skip it. I think if I was going to try to code this I might use an array[1..5] of records for results. The relationship between records in different columns is sort of tricky I guess logic would need to be added somehow . In some cases like pet fox it only said next to but not which side. I’d have to think about that