
P-99: Ninety-Nine Prolog Problems - kick
https://sites.google.com/site/prologsite/prolog-problems
======
wruza
I like the idea of walking around Prolog sometimes. But often it is used
against its seemingly main purpose. What do lists do there? Prolog should be
cool at tasks like: Pierre is french and never met a guy from 2nd floor at the
stairs, Joe has french friend who smokes, Bob likes Alice and living under the
roof, and Alice can’t stand cigarettes (and Bob); can Alice live in the same
house if it has only 3 floors?

Lists though seem so unnatural to logic problems, the same way they emulate
integers with lists in ‘too abstract’ lisps.

~~~
hahajk
One application that seems to me like it should be a natural fit for Prolog is
building a (human) schedule: class goes from 8-4, a student cannot take two
classes simultaneously, Joe is not available on Wednesdays, etc.

I forget the specifics but every implementation of such a schedule tends up
using lists and explicit recursion, (which I think is unpleasant in Prolog) In
fact, most moderately complex solutions of any problem I’ve seen fall back on
lists and explicit recursion. (I thought I was using Prolog to avoid all
that!) That’s probably a shortcoming of the language.

~~~
maweki
If you have such constraints, why not use a proper constraint system? Prolog
is in a (sometimes not so) sweet spots in terms of exploring search spaces.

For a problem like you've described, just write a SAT instance and be done
with it. And if you don't know how large your solution/search space is (even a
bound), then there's no alternative to creating lists and giving recursion
hints.

~~~
overlords
Most prolog implementations have finite domain constraints and constraint
handling rules, so you can work with constraints if that's more natural.

------
archielc
Scala's adaptation of this (S-99):
[http://aperiodic.net/phil/scala/s-99/](http://aperiodic.net/phil/scala/s-99/)

------
pgtan
Just make sure, solutions work in both directions.

------
photon_lines
If anyone is interested in implementing a mini prolog interpreter...I made a
toy one in python which you can find here:
[https://github.com/photonlines/Python-Prolog-
Interpreter](https://github.com/photonlines/Python-Prolog-Interpreter)

------
nitnelave
An example of a small Prolog program used in a perfect use-case: the advent of
code of this year.

[https://github.com/nitnelave/advent_of_code_2019/tree/master...](https://github.com/nitnelave/advent_of_code_2019/tree/master/04)

I'm doing the advent of code in a different language every day, and since the
day 4 was about some constraint resolution, Prolog was the perfect tool there.

~~~
tom_mellior
Nice. As a hint, you can unify free variables, i.e., variables not bound to
anything. Future bindings of those variables will respect the equality.

This means that you could write your password/1 predicate as something more
like:

    
    
        password(X) :-
          length(X, 6),
          has_2_equal_consecutive_digits(X),
          has_6_digits(X),
          is_value_in_range(X),
          digits_are_increasing(X).
    

That is, even _before_ filling the list with digits, you would already have
captured the constraint that two digits will have to be consecutive. Then,
while instantiating the list inside has_6_digits/1, something like 134567
would never even be generated, and you wouldn't need to test it for being in
range and having increasing digits.

------
simplify
Prolog / Datalog are beautiful languages. They should be in the repertoire of
more programmers.

------
krispyfi
I tried using Prolog for Advent of Code last year. It went okayish, but I seem
to recall that some things were unreasonably hard, such as reading from non-
Prolog-syntax files. I should give it another try this year. Maybe I missed
something obvious.

------
dontchooseanick
Obligatory fun clones :

* 99_Ninety-Nine_Lisp_Problems [http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/func...](http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)

* Ninety-Nine_Haskell_Problems [https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems](https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems)

* Ninety-Nine_Erlang_Problems [https://github.com/joelchelliah/ninety-nine_erlang_problems/...](https://github.com/joelchelliah/ninety-nine_erlang_problems/blob/master/README.md)

* ... Rust [https://github.com/MaskRay/99-problems-rust?files=1](https://github.com/MaskRay/99-problems-rust?files=1)

------
quotemstr
No.

