Hmm, seems like this could potentially be solved in a cool way using the amb operator. Might have to give that a shot later today.
Definitely. For anybody interested, http://mitpress.mit.edu/sicp/full-text/sicp/book/node90.html offers a nice introduction to the amb operator. One issue that I found when solving problems like this is that, to achieve speed, it can become necessary to use many nested let s. That could hurt readability. Nobody wants to see a line of code nested 20 tabs deep!
Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
11–20 of 23 posts
Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#12One way to elegantly describe and solve such a problem would be Answer Set Programming.
Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#13I also recommend a Mozart/Oz style interactive search tree explorer made by a student [2] .. built on fd.js.
[1] https://github.com/srikumarks/fd.js [2] http://minhtule.github.io/Search-Tree-Visualization/
Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#14Hmm, seems like this could potentially be solved in a cool way using the amb operator. Might have to give that a shot later today.
Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#15It's a really well-constructed puzzle, though: the identity of the fish owner is the very last part of the grid that you get to fill in.
Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#16Hmm, seems like this could potentially be solved in a cool way using the amb operator. Might have to give that a shot later today.
Haskell lists also work nicely for nondeterministic computation.
require :: Bool -> [()]
require True = return ()
require False = []
and then express amb-like computations in effectively the same way: sample :: [(Int, Int)]
sample = do
x
after which the value of sample is [(2,1),(4,2)]. (Also, my require is effectively the same as the guard function found in Control.Monad, specialized for lists.)Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#17It is a good illustration of code-as-data in Lisp. It's just that in this case, code-as-data doesn't seem to be a particular advantage in solving the problem (it's not a disadvantage either, just a stylistic difference).
So this article could have been 'A C solution to "Einsteins Riddle"' if C had been chosen as the language. Not a criticism, just a clarification, since HN is full of people looking for the true potential of new/different languages.
Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#18Re: Who owns the fish? A Common Lisp solution to "Einstein's Riddle" (2004)
#19In case anyone else misunderstood the title, this article doesn't demonstrate the unique ability of Lisp to solve this problem. The method they use is constraint solving using backtracking. This could be implemented in any language. It is a good illustration of code-as-data in Lisp. It's just that in this case, code-as-data doesn't seem to be a particular advantage in solving the problem (it's not a disadvantage eith…
Problem solving and algorithms exist independent of programming languages.
What's unique to this version here, is the use of a code generator.
http://www.weitz.de/files/einstein-minimize.lisp
> So this article could have been 'A C solution to "Einsteins Riddle"' if C had been chosen as the language.
The code would have looked vastly different.