This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (187)
- # aws (1)
- # aws-lambda (1)
- # beginners (162)
- # boot (64)
- # cljs-dev (6)
- # cljsjs (2)
- # cljsrn (32)
- # clojure (357)
- # clojure-greece (1)
- # clojure-korea (4)
- # clojure-russia (63)
- # clojure-sanfrancisco (3)
- # clojure-spec (91)
- # clojure-uk (63)
- # clojurescript (74)
- # clojurex (10)
- # code-reviews (55)
- # core-async (4)
- # core-typed (1)
- # cursive (17)
- # datascript (36)
- # datomic (43)
- # devcards (4)
- # dirac (3)
- # emacs (59)
- # hoplon (286)
- # jobs-discuss (399)
- # luminus (4)
- # mount (9)
- # off-topic (30)
- # onyx (53)
- # protorepl (3)
- # re-frame (88)
- # reagent (4)
- # spacemacs (1)
- # specter (14)
- # untangled (1)
- # vim (42)
one thing I'm doing is really looking at medley https://github.com/weavejester/medley/blob/master/src/medley/core.cljc sure to come in handy
weather up here: cold. -10C (14F). fireplace is on and working on some cljs so can’t complain 🙂
it’s an anglophone bastion in an otherwise bilingual-or-french-focused province, yep
unrelated: my colleague Angus Fletcher is doing AoC as well - https://github.com/angusiguess/advent-of-code2016 - he says you and he met in an elevator one time, not sure where haha
politically, in that rural provincial way. anecdote: there was a small chance that a strip club was going to open up. in order to thwart such an endeavor, the city swooped in and paid the lease on the empty building in question to eliminate the option. they are still paying that lease on that empty building to this day.
Isn't that what zoning laws are usually for? Hah. That's a painful way to solve a problem.
it wasn’t a small sum of money either; something like $500,000 for 5 or 10 years of empty building or something
(this particular building is right in the heart of downtown, so I suspect that’s why they are willing to go the distance to prevent it from happening)
yeah but geez the could have started a tech incubator, 3d printing shop, or something
(the building in question - former nightclub https://email@example.com,-66.6454743,3a,75y,43.99h,87.09t/data=!3m6!1e1!3m4!1sjwsC3AHYW5OjL7oYI3EZKg!2e0!7i13312!8i6656?hl=en )
though I’ll admit that my particular employer has done nothing but irritate me for lack of willingness to adopt cljs (even though our entire backend is clojure)
(I have yet to pull this off, because consulting is very, very difficult to pull that off with)
all of the above said WRT conservativeness @bhauman : it’s also a university town where the students make up something like 25% of our population during the school year, so there’s no small amount of more modern mindsets around
(defn rotate-left [v i] (let [c (count v)] (vec (take c (drop (mod i c) (cycle v))))))
I noticed one of the pinned ones was pretty compact, it just
(defn shift [l n] (let [n (- (count l) n) [first-part second-part] (split-at n l]] (vec (concat second-part first-part))))
I have a big soft spot for destructuring. This is what happens when you learn ML... >_>
Ahh, think I see. You'd perform mutations on the screen using transients, since the intermediates don't need to be used elsewhere.
(defn rotate-left [v x] (let [v (vec v) c (count v) offset (mod x c)] (loop [i 0 accum (transient )] (if (= i c) (persistent! accum) (recur (inc i) (assoc! accum i (get v (mod (+ offset i) c))))))))
With a structure this size, yeah. Would probably make some difference with more operations / a bigger 'screen'.
(defn rotate-left2 [v i] (let [c (count v)] (sequence (comp (drop (mod i c)) (take c)) (cycle v))))
I'm at a total loss today, I get completely different results when I paste today's string in raw than when I suck it in through a file. (the latter totally not being recognized by regexes even though it works fine when tested by hand)
if you’re having a hard time, then I feel as though I may have drastically underestimated the problem :^
.... /sigh. Okay, lesson learned. Good ol'
re-matches was stymied by the newline at the end of the input.
Given how often this seems to happen in these coding challenges, maybe I should come up with a quick set of parsing methods for easy utility...
More like 'lop off this pattern from the beginning, hand me the matched groups and the remainder of the string'
well all the test cases pass, and everything seems correct, but says I have the wrong answer
mnespor, for the last one, do you build out a string still or do you just consume the string and find the length?
The recursion depth doesn't require trampoline, though I did end up using mutual recursion...
I just consume the string and find the length. Tail call optimization turned the recursion into a loop for me
I consume characters until the first marker, drop the marker, and push its expansion back into the input
(def data (string/trim (slurp (io/resource "day9.txt")))) (defn parse-dir [d] (let [[_ directive & args] (re-matches #"(\((\d+)x(\d+)\)).*" (apply str d))] (cons (u/to-ints args) (list (drop (count directive) d))))) (defn parse-directive [d] (let [[[cnt rpt] xs] (parse-dir d) part (take cnt xs)] [(apply concat (repeat rpt part)) (drop cnt xs)])) (defn parse* [accum d] (cond (empty? d) accum (= (first d) \() (let [[res rst] (parse-directive d)] #(parse* (vec (concat accum res)) rst)) :else #(parse* (conj (vec accum) (first d)) (rest d)))) (defn parse [d] (trampoline parse*  d))
In the end you're building a string that's hundreds of thousands, if not millions of characters long
Consider this: inside of a repetition tag and the region it affects, do any of the tags have any influence on characters outside of that region?
I'm pretty sure they only generate input that satisfies the above. It could be I got a lucky input, but that seems like a constraint they intended to add, given the 'not enough memory to decompress' comment.
In this case, the first (9x2) ends at E, but the nested (9x2) covers up to I:
(9x2)(9x2)ABCDEFGHIJ (9x2)ABCDE(9x2)ABCDEFGHIJ ABCDE(9x2ABCDE(9x2)ABCDEFGHIJ ABCDE(9x2ABCDEABCDEFGHIABCDEFGHIJ
(wasn't there a puzzle last year that asked you to tailor your solution to your input instead of solving the general case?)
I don't recall, but that implicit constraint is almost necessary to make the problem work as desired here.
I mean you could still have an algorithm that does that, and just assumes you'll return to the original string to consume when you run out of characters in the current region... but at that point you're in this really weird state, where the order of evaluation doesn't actually make sense....
hmmm wait a minute it looks like processing it backwards may be equivalent for problem 2
(well, ignoring the parenthesis overlap, but you get the idea of how this could play out)
What might that look like? It's probably not enough to seek backward to the first marker:
(5x3)(5x3)AAAB (5x3)AAAAAAAAAAAAAAAB AAAAAAAAAAAAAAAAAAAAAAAAAB
I think they tailored the input such that you don't have to worry about boundary crossing like that, too much ambiguity involved
It won't be.
(5x3)(5x3)AAAAB would expand to
(5x3)(5x3)(5x3)AAAAB if evaluated from the left, and that clearly blows up
It's boundary crossing if the inner input consumes characters beyond the outer input
That makes working backward complicated.
(6x3)(1x3)A is valid forward, but not backward
B. The examples they give work left to right, outer to inner, and I think that's an intentional cue
So it should be equivalent to the 'expand single tag and prepend the result' method
But you can chop out a bunch of work assuming that the boundary is never crossed, since that leads to absurd ambiguities in the spec
From the spec for part 1: > To decompress this marker, take the subsequent 10 characters and repeat them 2 times. Then, continue reading the file after the repeated data.
My next move would be to quit bouncing between seqs and strings and using regexes, and just manually chew through the character stream instead
But even as I have it now, string conversions and all, the calculation time is very short
Hey I was a bit late to start todays... I'm on part 2 and I'm wondering if we are agreeing or not whether the boundaries can overlap?
It seems you could just parse it recursively if you don't allow overlap. That would be nice...
Based on a sample set of one - my own - I don't believe they intended for boundaries to overlap, no.
(spoilers) Here's some discussion on boundary crossing in day 9 inputs: https://www.reddit.com/r/adventofcode/comments/5hgd1f/day_9_part_2_everyone_assumes_it_but_its_not/dazzrm5/
The part I don't understand is, "The puzzle is about trying to get the user to do some kind of recursive expansion". But can you assume recursive expansion will work? I thought, "You can't"
Since no boundaries are crossed, you can safely say 'recursively count the decompression of this tag's region. Now multiply by this tag's number of repetitions.'
The recursion level is pretty flat for most inputs I'm guessing, so very little stack problems and you can deal with finite chunks of the input at a time.