core-logic

schmee 2018-11-27T06:55:21.045300Z

here’s the actual thing:

(run* [q]
    (init vars legs)
    (with-fresh
      (membero ?1 vars)
      (membero ?2 vars)
      (membero ?3 vars)
      (membero ?4 vars)
      (== ?1 ["M" ?a1 ?b1])
      (== ?2 ["T" ?a2 ?b2])
      (== ?3 ["W" ?a3 ?b3])
      (== ?4 ["R" ?a4 ?b4])
      (== ?b1 ?a2)
      (== ?b2 ?a3)
      (== ?b3 ?a4)
      (== q [?1 ?2 ?3 ?4]))))

schmee 2018-11-27T06:55:47.045800Z

vars is a collection of tuples like this: ["M" "SAN_ANTONIO" "HOUSTON"] (day of week, start, end)

schmee 2018-11-27T06:56:19.046200Z

I’m messing around with a core.logic solution to https://kevinlynagh.com/notes/shipping-puzzle/

schmee 2018-11-27T06:57:08.047100Z

but running the above with just 100 tuples take 15 minutes to produce one result

schmee 2018-11-27T06:58:31.047900Z

(`with-fresh` just binds all ? variables to a fresh lvar)

2018-11-27T19:19:02.048900Z

How much faster does it go if you move the memberos to the end?