[HN Gopher] Solving a "Layton Puzzle" with Prolog
       ___________________________________________________________________
        
       Solving a "Layton Puzzle" with Prolog
        
       Author : Tomte
       Score  : 38 points
       Date   : 2025-04-08 19:11 UTC (3 hours ago)
        
 (HTM) web link (buttondown.com)
 (TXT) w3m dump (buttondown.com)
        
       | taeric wrote:
       | Very fun post! If folks haven't seen it, Knuth's latest release
       | looks at constraint satisfaction. Really fun discussion on the
       | relations between different ways to model this sort of problem.
       | Happy to add this book to my list!
       | 
       | I would also challenge the author to consider puzzles a bit more.
       | Sprinkling fun into the topics goes a long way. Specifically, do
       | both! Talk about how you can reframe a "real world" problem in
       | terms of some puzzles we may have played as kids. Invite us to
       | play more as adults.
        
       | trainyperson wrote:
       | Doing the puzzle with "pencil and paper" logic is actually quite
       | approachable and fun! I recommend it. Hint: you don't need to run
       | constraint satisfaction! There are some insightful shortcuts to
       | be made
        
       | NooneAtAll3 wrote:
       | if anyone wants a "human" solution
       | 
       | 1) there are 4 questions that everyone answered the same way
       | (let's say this earned everyone A points)
       | 
       | 2) in the rest of the questions, 7-point and 5-point students
       | gave opposite answers
       | 
       | that means that 7-A (rest of 7-point student's correct answers)
       | equals to 5-(4-A) (rest of 5-point student's incorrect answers)
       | 
       | 7-A = 1+A => A=3
       | 
       | That means 3-point student scored 3 points together with everyone
       | else, and answered rest of the questions wrong
       | 
       | From this it's trivial to find the hidden score and why there are
       | 4 possible answer keys
        
       | crtasm wrote:
       | A puzzle from a game in this series
       | https://en.wikipedia.org/wiki/Professor_Layton
        
       | jfengel wrote:
       | The puzzle is easy enough to solve by brute force, but it seems
       | like rather a lot to solve by hand for a very junior-targeted
       | game.
       | 
       | Heuristics could reduce trial-and-error to a reasonable search
       | space, but is there a purely deductive way to solve this by hand?
        
         | Jtsummers wrote:
         | With the 4 common answers (all 4 people answered them the same)
         | we know that no more than 3 of them can be correct (because
         | Lisa scored 3 points). We also know at least one must be
         | correct (otherwise Mary can't score 7).
         | 
         | Examine what Mary and Dan have in common besides those 4...
         | Nothing. They disagreed on each of the remaining 6 answers.
         | 
         | We can break this down into three cases, either 1, 2, or 3 of
         | the common answers are correct:
         | 
         | 1 - Impossible. Mary gets 6 of the remaining correct, Dan gets
         | 4 of the 6 remaining correct, but they have none in common so
         | this doesn't work.
         | 
         | 2 - Impossible. Mary gets 5 of the remaining correct, Dan gets
         | 3 of the remaining correct, but again their answers disagree so
         | they cannot share a common answer out of the 6 remaining.
         | 
         | 3. Mary needs 4 of the remaining 6 and Dan needs 2, this is
         | feasible.
         | 
         | At this point you can ignore the 4 common ones other than to
         | say Colin has at least a score of 3.
         | 
         | Since we now know that everything outside those common ones are
         | incorrect for Lisa, cross everything off that Lisa and Colin
         | share of the 6 non-common answers. There are only 3 that
         | disagree with Lisa so they must be correct (because everything
         | Lisa answered here is wrong). This gives Colin a final score of
         | 6, three in common with everyone and three from disagreeing
         | with Lisa.
         | 
         | The reason there are 4 keys in Hillel's solution is actually
         | kind of funny, they don't matter. Those 4 keys only disagree on
         | which of the 4 common answers are incorrect. They agree
         | everywhere else.
         | 
         | EDIT: Presentation and some typos
        
         | supernewton wrote:
         | Dan and Lisa's answers agree on all but problems 6 and 9, and
         | Dan got two more correct than Lisa. So Dan is correct on both 6
         | and 9. Therefore, Mary is incorrect on 6 and 9. So she got
         | seven of the other eight correct, and Dan got three of the
         | other eight correct. But on those eight problems, Mary and Dan
         | disagree on only problems 2, 3, 5, and 10, therefore Mary got
         | all four of those correct. Then Mary got three of problems 1,
         | 4, 7, 8 correct, but everyone answered the same way on those,
         | so Colin got three right on those problems as well. Then read
         | off the deduced answer key for the other six problems to get
         | Colin's final score.
        
       | AceJohnny2 wrote:
       | Related: https://news.ycombinator.com/item?id=35623625 (2023)
       | "Why Did Prolog Lose Steam (2010)"
       | 
       | Anecdotally, some years ago the Zebra Puzzle [1] made the rounds
       | in my team. Two people solved it: myself, a young intern, who
       | mapped out the constraints as a physical puzzle that I was able
       | to solve visually, and a more seasoned colleague who used Prolog.
       | 
       | [1] https://en.wikipedia.org/wiki/Zebra_Puzzle
        
       | superlopuh wrote:
       | I once used Sentient[0] to solve a similar puzzle in a different
       | game that I think made a puzzle that required a constraint solver
       | as a joke on the player. I'm a bit saddened to see that the repo
       | hasn't been updated in 6 years, and a node update broke the
       | binary installed on my computer, I find it a much more ergonomic
       | environment than Prolog, hopefully someone else will pick up the
       | mantle.
       | 
       | [0]: https://sentient-lang.org/
        
       | tannhaeuser wrote:
       | Don't understand why the article uses SWI's constraint libs when
       | the problem is easily solved using pure ISO Prolog with code
       | readily linked from the article even ie Pablo's solution at [2].
       | 
       | Just paste that code into [1] and append the line (or place it at
       | the start, doesn't matter)                   :-
       | initialization(colin_score(X)).
       | 
       | to tell Prolog which top-level goal to solve and hit Execute to
       | see the solution in your browser.
       | 
       | [1]: https://quantumprolog.sgml.net/browser-demo/browser-
       | demo.htm...
       | 
       | [2]: https://morepablo.com/2010/09/some-professor-layton-
       | prolog.h...
        
       ___________________________________________________________________
       (page generated 2025-04-08 23:00 UTC)