Fork me on GitHub
#core-logic
<
2020-12-16
>
erwinrooijakkers20:12:34

Hi I am trying to solve the last part of day 16 of aoc using core.logic

erwinrooijakkers20:12:49

spoiler maybe so I put it in comment

erwinrooijakkers20:12:30

The idea is that we know for twenty indexes what the possible values are. Iteratively, you can eliminate a field where there is only one solution from all the others, since you know that (below for example) i13 MUST be 8 since it is the only option. Then you eliminate 8 from the values and you see that i11 must be 6. How do I code this in core.logic? I tried:

(run* [q]
  (fresh [i0 i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20]
    (logic/== q [i0 i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20])
    (fd/in i0 i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 (fd/interval 0 21))
    (logic/membero i0 #{1 2 3 5 6 8 10 11 14})
    (logic/membero i1 #{0 1 2 3 4 5 6 8 10 11 14 15})
    (logic/membero i2 #{0 1 2 3 4 5 6 7 8 10 11 14 15 18 19})
    (logic/membero i3 #{1 2 3 4 5 6 8 10 11 14})
    (logic/membero i4 #{0 1 2 3 4 5 6 8 10 11 14})
    (logic/membero i5 #{6 8 10 11})
    (logic/membero i6 #{6 8 11})
    (logic/membero i7 #{1 5 6 8 10 11 14})
    (logic/membero i8 #{6 8 10 11 14})
    (logic/membero i10 #{1 2 5 6 8 10 11 14})
    (logic/membero i11 #{6 8})
    (logic/membero i12 #{1 6 8 10 11 14})
    (logic/membero i13 #{8})
    (logic/membero i14 #{0 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19})
    (logic/membero i15 #{0 1 2 3 4 5 6 7 8 10 11 14 15 17 18 19})
    (logic/membero i16 #{0 1 2 3 4 5 6 7 8 10 11 14 15 16 17 18 19})
    (logic/membero i17 #{0 1 2 3 4 5 6 7 8 10 11 12 14 15 16 17 18 19})
    (logic/membero i18 #{0 1 2 3 4 5 6 8 10 11 14 15 19})
    (logic/membero i19 #{0 1 2 3 4 5 6 8 10 11 14 15 18 19})
    (logic/membero i20 #{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19})))

;; => ()
It should, however, be
;; => (3 15 7 4 0 10 11 5 14 2 6 1 8 9 17 16 12 19 18 13)

paulocuneo20:12:16

no quite sure, but I think core logic membero doesnt handle sets #{}. try using vector instead. didn't understand your solution (is this the puzzle https://adventofcode.com/2020/day/16 ?)

erwinrooijakkers20:12:50

Hope someone can take a look and help me make it work