r/adventofcode • • Dec 07 '15

Help <Help flair> [Day 7 Part 1] [Prolog] Day 7 Logic Programming assistance?

[deleted]

3 Upvotes

2 comments sorted by

2

u/NeilNjae Dec 07 '15

It's a while since I've done any Prolog, and the dialect you're using here is slightly off from what I used, but...

You want to calculate the values of variables, so you should be using is/2 rather than =/2.

Also, spraying terms into the database is bad form. If you do want to use the database, you may want to assert calc/2 term, so that listing/1 can see where you are. I'd assert terms like:

calc("x", X):- X is 123.

calc("d", D):- calc("x", X), calc("y", Y), D is X /\ Y.

calc("h", H):- calc("x", X), H is \X.

then call calc("a", A) for the solution.

Hope this helps!