This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-16
Channels
- # adventofcode (99)
- # announcements (2)
- # babashka (37)
- # beginners (111)
- # cider (4)
- # cljsrn (5)
- # clojure (51)
- # clojure-australia (2)
- # clojure-chicago (3)
- # clojure-europe (141)
- # clojure-nl (2)
- # clojure-provo (2)
- # clojure-spec (48)
- # clojure-sweden (2)
- # clojure-uk (26)
- # clojurescript (34)
- # conjure (1)
- # core-logic (5)
- # cursive (16)
- # datomic (2)
- # events (2)
- # fulcro (54)
- # graphql (13)
- # jobs-discuss (116)
- # kaocha (14)
- # meander (101)
- # off-topic (41)
- # pathom (6)
- # planck (3)
- # re-frame (53)
- # reagent (10)
- # reitit (1)
- # reveal (13)
- # shadow-cljs (35)
- # spacemacs (22)
Hi I am trying to solve the last part of day 16 of aoc using core.logic
spoiler maybe so I put it in comment
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)
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 ?)
Hope someone can take a look and help me make it work