This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-09
Channels
- # adventofcode (201)
- # bangalore-clj (5)
- # beginners (90)
- # cider (1)
- # cljs-dev (3)
- # cljsrn (28)
- # clojure (128)
- # clojure-argentina (1)
- # clojure-brasil (15)
- # clojure-dev (9)
- # clojure-greece (18)
- # clojure-italy (11)
- # clojure-madison (1)
- # clojure-poland (19)
- # clojure-russia (28)
- # clojure-spec (33)
- # clojure-uk (26)
- # clojurescript (20)
- # core-async (2)
- # cursive (1)
- # datomic (2)
- # emacs (4)
- # figwheel (3)
- # fulcro (15)
- # graphql (7)
- # hoplon (1)
- # lein-figwheel (2)
- # lumo (2)
- # numerical-computing (3)
- # off-topic (9)
- # re-frame (13)
- # ring (1)
- # shadow-cljs (1)
- # unrepl (1)
- # vim (17)
Yak-shaved today's. (Spoiler alert, obv) Initial solution https://github.com/armstnp/advent-of-code-2017/blob/f013cff13592e2cbffff0cd6fa9aee8662d1cb1c/day-9.clj Refactored solution https://github.com/armstnp/advent-of-code-2017/blob/ff41b881cf016148e927ff01ac44ed65ec445a08/day-9.clj
I do love my iterate, but now that you say something reduce is probably more appropriate.
Eh, never mind. Might have worked if I'd kept the stream separate from the accumulated state, but part of the problem is that one of the 'instructions' modifies the stream itself, which makes function outputs weirder.
Hmm. Not sure if you're just lucky or not, but !
only ignores the next character while inside a garbage block, according to the problem statement
@fellshard I read the problem statement as the futile ! were only inserted inside garbage, so I could just strip it away, as I don’t expect ! outside < >
@fellshard ok, if you have a link to your input + your expected answers I can give it a ty
https://github.com/armstnp/advent-of-code-2017/blob/master/day-9.clj Score: 17390 Garbage: 7825
@fellshard my program works for my input + the examples
Turned out my first solution was correct after all. I just copied the quoted input to a file, which yielded a different answer. DOH.
Ick. My bad. I should really get a repl on my personal machine so I can use resource files instead, like you do. Easier to wrangle and share.
Wait, yes it does. >
will exit a garbage block if you're in one, or have no effect if you're not.
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day09.clj
@bhauman @fellshard pointed out my program was incorrect for his input. I tried yours and get same numbers as you now (not pushed yet). Could you try his input? I get a different number for the garbage. https://github.com/armstnp/advent-of-code-2017/blob/master/day-9.clj Score: 17390 Garbage: 7825
Very nice PureScript solution: https://github.com/krisajenkins/AdventOfCode/blob/master/src/Year2017/Day9.purs
@nooga mine is similar but I reduced the states of the automaton by handling the score separately
My day 9: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_09.cljc
so I'm thinking I can clean the garbage up with string/replace now that I know it takes a fn arg
@grzm I think you can convert (condp = c \a (foo) \b (bar) :else (baz))
to (case c \a (foo) \b (bar) (baz))
and in addition to the simplification, you get a perf improvement with constant-time dispatch.
Nice @nooga. I tried yours on my input, and as you'd expect your version runs more quickly (it shaves off 25–50% or so)
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day09.clj
Why is this so sloooooow?
(s/def ::garbage (s/cat :lab #{lab}
:content (s/* char?)
:rab #{rab}))
(s/def ::group (s/cat :lcb #{lcb}
:children
(s/* (s/cat :child (s/alt :group ::group
:garbage ::garbage)
:comma (s/? #{\,})))
:rcb #{rcb}))
(s/conform ::group (seq "{{},{<x>}}"))
(defn parse-string [s]
(s/conform ::group (seq s)))
(comment
(def p (parse-string (data))))
Heap space exception@mfikes Oh cool (isomorphic), but mine is incorrect for one out of three inputs I tried
I was also thinking of rewriting it to dispatch on both args to move all dispatch logic into the multimethod.
@mfikes I noticed yours failed too for @fellshard’s input (returns 8373 for garbage count instead of 7825)
So, some part of the problem definition seemed underspecified to me, and I ended up assuming.
@borkdude mine now uses regexes like yours did and it works for @fellshard's input
@bhauman you’re replacing the exclamation marks regardless of whether they occur out or inside the question marks… but it seems they don’t ever occur outside
if I had a better up front understanding of the structure, e.g. {aaaxx!xxx{<x>}} doesn’t occur, I would have written a better solution… but to eager too find the answer 🙂
thats the cool thing about str/replace taking a function, is you can call str/replace again inside that fn
Wait, that's exactly the part that I thought was underspecified in the problem definition @borkdude
> In a futile attempt to clean up the garbage, some program has canceled some of the characters within it using !: inside garbage, any character that comes after ! should be ignored, including <, >, and even another !.
Yeah, my code does that as well, but I would claim my code is undefined for that kind of input.
I'm leading towards {aaa{foo}xxx}
being a single group, because "things" are separated by commas
@mfikes I ignored commas too, I treat all things like whitespace if it’s not a group / garbage separator
the presense of non garbage garbage, doesn't affect the final score or the garbage count
I wonder what’s up with the garbage count in our code mfikes…. — yes, you’re right bhauman, I think we’re doing that
but he told me he got 7825 and bhauman + Vik got that too: https://twitter.com/pg_xocolatl/status/939517141606457344
For fellshards input my code produces 17390 and 8373 and fellshard's produces {:score 17390, :garbage-count 8373}
@borkdude I think the problem is this: In fellshard's code his input is defined in the code. I copied your input file in your repo, but the file is a direct copy, and the file has the quotes escaped in it
So, I'm getting the incorrect answer for the file, but the correct one from the literal code
In other words, the problem is here https://github.com/borkdude/aoc2017/blob/master/resources/day9-fellshard.txt at the first escaped quote
@nooga yeah its not easy but I hurt my back the other day so i'm kinda stuck on the couch
I think my spec is correct now, but it’s still slow: https://github.com/borkdude/aoc2017/blob/master/src/day9_spec.clj#L56
Surprisingly when I replaced the defmulti with one big multi-tiered case statement, it's slower. https://github.com/grzm/advent-of-cljc/blob/899b18e6e72ce2157d63f9b3b7280b1c35a0f106/src/main/com/grzm/advent_of_code/advent_2017/day_09/part_1.cljc
That makes sense. It's building up some sort of structure to be able to explain failures.
@borkdude I think your specs are slow because the :content and :rab branches are not mutually exclusive because char? will also match rab. So it "blabla>yadayadayada" will parse as the whole string into :content first and then will need to backtrack
Hi all! I had to solve this in a real hurry today, here is my solution: https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day9.clj
@borkdude I've been eyeing your resource-reducible
. I've been focusing on using more tranducers. Is that something you worked out yourself?
@grzm No, I stole it from a blog post, but you can see the idea here: https://stackoverflow.com/questions/47333668/split-lines-in-clojure-while-reading-from-file/47354316#47354316
One more piece to have in my back pocket. AoC, or rather, this community in AoC, has been really helpful for me. Thanks, all of you!
That may very well be the case, but if you didn't have it there, I wouldn't have been exposed to it. So regardless of whether you needed it, it served a purpose.
Ah, I should have used letfn for my mutually recursive functions instead of pre-declaring them.
Inlined the grammar now, so you see the entire solution one file. See above link. Really happy with it 🙂
I think you could do the same with spec in hindsight as @thegeez said, more restricted rules/predicates. The nice thing with Instaparse is that you can hide tags and output. Not sure if that’s possible with spec. That would be nice in fact.
Here’s a screenshot of the parsetree: https://twitter.com/borkdude/status/939583561568604160
@grzm for resource-reducible there's also https://github.com/cgrand/xforms/blob/master/src/net/cgrand/xforms/io.clj#L14
Howdy all 🙂. So.. day 9. I ended up with a couple of weirds constructs for dropping cancelled chars (and to drop garbage): https://github.com/metamorph/advent-of-code-2017/blob/master/adv2017/src/adv2017/day9.clj#L1 (`make-drop-!-xf`) where I use an atom to keep state in a filter. I'm thinking that there must be a better way of doing that (and still being "lazy"). Any suggestions?
@gnejs There is a possible solution with a single pass using a couple of values in a state with reduce
For reference here is my solution https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_09.cljc
@borkdude that's cool. 🙂 I was trying to split apart the concerns of "cancelling" and "dropping garbage" into separate transducers to avoid one big reducing function with all aspects mixed.
So my question is really - how do you implement a stateful filter (transducer-like) without resorting to using mutable state as I did?
@gnejs I think it is normal to keep state (usually using volatiles instead of atoms). See (source distinct)
I honestly don't know too much about it other than "stateful transducers have mutable state in them using volatiles"
Didn't know about volatile!
before. Thanks for the pointer :thumbsup: This seems to be pretty exhaustive explanation: https://stackoverflow.com/questions/31288608/what-is-clojure-volatile/31319731#31319731