<story><title>Logic Puzzles with Prolog (2017)</title><url>https://www.metalevel.at/prolog/puzzles</url></story><parent_chain><item><author>umvi</author><text>Prolog really blows my mind.&lt;p&gt;I recently released a match-burning logic puzzle app[1] based on a mensa calendar puzzle I saw and it took me a while to develop an (imperfect) solver algorithm in C#. Someone then told me that the general class of these puzzles is called &amp;quot;Thermometer Puzzles&amp;quot; and that there are a ton of Prolog-based solvers[2] out there.&lt;p&gt;This class of puzzle is not mentioned in the article, but I&amp;#x27;m truly amazed at how versatile Prolog is at solving logic puzzles with so little code. I&amp;#x27;m guessing the Prolog compiler is super complex compared to, say, a C compiler to be able to give developers that much power.&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;play.google.com&amp;#x2F;store&amp;#x2F;apps&amp;#x2F;details?id=com.umvirate.embergram&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;play.google.com&amp;#x2F;store&amp;#x2F;apps&amp;#x2F;details?id=com.umvirate.e...&lt;/a&gt;&lt;p&gt;[2] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;zettca&amp;#x2F;ist.lp.thermometers&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;thermometers.pl&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;zettca&amp;#x2F;ist.lp.thermometers&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;th...&lt;/a&gt;</text></item></parent_chain><comment><author>mthom</author><text>&amp;gt; I&amp;#x27;m guessing the Prolog compiler is super complex compared to, say, a C compiler to be able to give developers that much power.&lt;p&gt;They&amp;#x27;re not that complex. I&amp;#x27;m writing one from scratch right now:&lt;p&gt;&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;mthom&amp;#x2F;scryer-prolog&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;mthom&amp;#x2F;scryer-prolog&lt;/a&gt;&lt;p&gt;Speaking of constraint solvers, the author of Power of Prolog, Markus Triska, is now in the process of porting his clp(ℤ) constraint solver over to my system, having already ported his boolean constraint solver, clp(B). They are quite complex, but it helps that they&amp;#x27;re written entirely in Prolog.</text></comment>
<story><title>Logic Puzzles with Prolog (2017)</title><url>https://www.metalevel.at/prolog/puzzles</url></story><parent_chain><item><author>umvi</author><text>Prolog really blows my mind.&lt;p&gt;I recently released a match-burning logic puzzle app[1] based on a mensa calendar puzzle I saw and it took me a while to develop an (imperfect) solver algorithm in C#. Someone then told me that the general class of these puzzles is called &amp;quot;Thermometer Puzzles&amp;quot; and that there are a ton of Prolog-based solvers[2] out there.&lt;p&gt;This class of puzzle is not mentioned in the article, but I&amp;#x27;m truly amazed at how versatile Prolog is at solving logic puzzles with so little code. I&amp;#x27;m guessing the Prolog compiler is super complex compared to, say, a C compiler to be able to give developers that much power.&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;play.google.com&amp;#x2F;store&amp;#x2F;apps&amp;#x2F;details?id=com.umvirate.embergram&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;play.google.com&amp;#x2F;store&amp;#x2F;apps&amp;#x2F;details?id=com.umvirate.e...&lt;/a&gt;&lt;p&gt;[2] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;zettca&amp;#x2F;ist.lp.thermometers&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;thermometers.pl&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;zettca&amp;#x2F;ist.lp.thermometers&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;th...&lt;/a&gt;</text></item></parent_chain><comment><author>DannyB2</author><text>If you want to know how to build a Prolog . . .&lt;p&gt;When I learned Common Lisp, I devoured the available textbooks in 1989 and for a few years after.  A book from the early 1990s is: Paradigms of AI Programming: Case Studies in Common Lisp.  By Peter Norvig (now employed by Google)&lt;p&gt;The book first teaches you Common Lisp, which isn&amp;#x27;t that difficult to pick up.  But that itself is a transformative experience.&lt;p&gt;Then the book shows you how to build a number of amazing things using Common Lisp.  It starts IIRC, with pattern matching.  Term rewriting.  Unification matching.&lt;p&gt;Then you proceed to build a few things like:&lt;p&gt;1. A program that solves high school style algebra word problems.&lt;p&gt;2. A &amp;quot;prolog&amp;quot; (but expressed in Lisp syntax) that is a &amp;quot;hair&amp;#x27;s breadth&amp;quot; (in the author&amp;#x27;s words) from real prolog.&lt;p&gt;This book was mind blowing.  A revelation.  Insightful.&lt;p&gt;Learning Lisp (even from other textbooks before the one I mention here) was a transformative experience.  But this single book stands out in providing so many amazing ideas expressed in Lisp.&lt;p&gt;Other Lisp texts I had read taught me things like playing two-player zero sum games (TicTacToe, Checkers, Reversi).  I abstracted the technique to have a single re-usable AI engine implementing the Minimax with Alpha-Beta pruning, and then different layers on top of that which implemented different games (as listed earlier) by defining a game board, move generator and board scoring function.&lt;p&gt;One Lisp textbook I had from the late 1980s showed a program to plan movements of a robot arm to manipulate blocks according to english like commands.&lt;p&gt;All of these amazingly sophisticated things take up very little Lisp code.  Often only a few pages.&lt;p&gt;The journey of learning Lisp, with a really good textbook, is an amazing learning experience.  Learning Lisp will change the way you think about code for the rest of your entire life.  I can confidently say that having learned Lisp starting in about 1986 and dabbling with it through 1993.  The initial learning comes quickly.  But you will play with this new toy for a long time.&lt;p&gt;Another book (The Elements of Artificial Intelligence Using Common Lisp) introduced me to the A-star search.  I&amp;#x27;ve used that technique, in Java, to build a &amp;quot;solver&amp;quot; for a game sometimes called &amp;quot;Traffic Jam&amp;quot; or &amp;quot;Unblock Me&amp;quot;.</text></comment>