This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-15
Channels
- # adventofcode (80)
- # beginners (94)
- # biff (19)
- # cider (74)
- # clj-kondo (11)
- # cljs-dev (7)
- # clojure (110)
- # clojure-austin (3)
- # clojure-australia (1)
- # clojure-belgium (1)
- # clojure-china (1)
- # clojure-europe (83)
- # clojure-filipino (1)
- # clojure-hk (1)
- # clojure-indonesia (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (1)
- # clojure-norway (4)
- # clojure-sg (1)
- # clojure-taiwan (1)
- # clojure-uk (2)
- # cursive (3)
- # data-science (8)
- # datalevin (8)
- # emacs (18)
- # etaoin (5)
- # graalvm (1)
- # holy-lambda (3)
- # honeysql (1)
- # jackdaw (9)
- # java (10)
- # jobs (3)
- # luminus (9)
- # malli (106)
- # off-topic (88)
- # polylith (8)
- # portal (2)
- # re-frame (50)
- # reagent (11)
- # reitit (74)
- # remote-jobs (1)
- # shadow-cljs (46)
- # tools-deps (26)
- # xtdb (49)
If a position is occupied by B then that position doesn't count for part1, correct? How about the position of S?
I used pmap and got my part 2 runtime down to about 2.5 minutes. Still seems slow. https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_15_beacons.clj
https://gitlab.com/maximoburrito/advent2022/-/blob/main/src/day15/main.clj Not proud in any way of this code. Sad to say I spend OVER 30 minutes debugging part1 only to realize I was checking y=10 from the sample input and not the y for the real input... UGGH... I had to write a couple version of part2 before I got it right. I didn't reuse much code between part1 and part2. "Elapsed time: 31199.856226 msecs"
optimizing this problem is hard, I've reordered points and suddenly it solves in 4 seconds - just because my answer is close to edge and with the new order it needs to brute force through less data
part 2 takes some 30 seconds but hey, it works! my previous record was completing day 14 so I'm happy that's as far as I ever got 🎉 https://github.com/FelipeCortez/advent-of-code/blob/master/2022/15.clj
(defn merge-intervals [intervals]
(get
(reduce (fn [[nb-open last retval] [x dir]]
(if (= -1 dir)
[(inc nb-open) (if (zero? nb-open) x last) retval]
[(dec nb-open) last (if (= 1 nb-open) (conj retval [last x]) retval)]))
[0 nil []]
(->>
(concat (map #(list (first %) -1) intervals)
(map #(list (second %) 1) intervals))
(sort-by second)
(sort-by first))) 2))
(defn part1 [rowy inputs]
(let [intervals (keep (fn [[x1 y1 x2 y2]]
(let [dist (+ (abs (- x2 x1)) (abs (- y2 y1)))
dist-at-row (- dist (abs (- rowy y1)))]
(when (>= dist-at-row 0)
[(- x1 dist-at-row) (+ x1 dist-at-row)])))
inputs)]
(merge-intervals intervals)))
(defn part2 [inputs]
(doall
(for [y (range 4000000)]
(let [intervals (part1 y inputs)]
(when (> (count intervals) 1)
(println y intervals)))))
nil)
(->> (slurp "day15.txt")
(str/split-lines)
(map (fn [line]
(map parse-long (str/split line #" "))))
(part1 2000000))
(->> (slurp "day15.txt")
(str/split-lines)
(map (fn [line]
(map parse-long (str/split line #" "))))
(part2))
(spoilers) of course https://www.reddit.com/r/adventofcode/comments/zmfwg1/2022_day_15_part_2_seekin_for_the_beacon/. how did I not think of that
Wrong parsing killed me today... https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2022/day15.clj
I tried out my idea that I was pondering last night, and Part 2 runs in 41 msecs. Yahoo!
Reading above, it looks like my approach must be similar to @U051HUZLD ’s
I'm just flailing on this day, for some reason. My first submission for part 1 was too low. Every change/adjustment I've made to the code since then keeps returning the exact same answer.
What is weirding me, is that every change yields the same answer. If there were something wrong with the algorithm I would expect SOME variation...
Today's case is really hard to debug imho. I was reading squares manually to be sure I'm right (or wrong).
https://github.com/genmeblog/advent-of-code/blob/master/resources/advent_of_code_2022/day15.txt
@UEF091BP0 not sure what you’re using, but sometimes when I get crazy results like that, it’s because I have some old function compile in my cache. restarting takes care of it.
@UEF091BP0 how are you handling becons in the row?
Sadly, when I run for the actual answer I use a lein run
process to make sure it's a clean VM.
I don't count beacons in the row... should I be? The example specifically doesn't count the one beacon in its row.
I had exactly the same, other imput was correct, mine not. Maybe verify parsing again?
So the abs difference between -2 and 24 is 26. But its inclusive so its actually 27 entries minus the beacon.
Also, I think I’ve mentioned before about how edn/read-string
is a great way to parse …. :face_with_hand_over_mouth:
Parsing checks out. What I am doing is running along the given y from (min-x, max-x). For each (x,y) pair, I look to see if it isn't a beacon, and if it is in range of at least one sensor. This gave me the correct answer for the other input data, just not for mine.
Possible. They are calculated by finding the min-X from the sensors, then subtracting it's beacon distance from it. Do the same with max-X and +.
I can tell you a number that your max shouldn’t be below if you want. It’s something you learn in from the second part.
@UEF091BP0 hmmm actually your bounds algorithm sounds wrong
@UEF091BP0 because the (min-x sensor + beacon dist) might not be the the absolute min-x
Oh $^!%. I think it might actually be freakin' typo. Just found something sus when verifying my bounds code.
@UEF091BP0 did you see my messages above?
Yes, I did. It's (min-x sensor minus beacon dist), then (max-x sensor plus beacon dist).
@UEF091BP0 (min-x sensor minus beacon dist) isn’t nessearily the min-x
@UEF091BP0 because the middle-x sensor may have a huge beacon dist
Yeah, that was sarcasm 🙂. Even before reading part 2, I knew the gist of it. Not even sure where to start...
Finished writing a lot of notes to explain my approach. I’m quite pleased with it. https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_15_beacons.clj I need to go back and adapt part 1 to use it, I think I have a way to do it.
a pretty naive approach, checking each row for spans covered and merging those. pt2 runs in ~36 seconds edit: a bit of hacking away with some threads to use all my cores and I can get pt2 down to about 6.5s
Had no time yesterday.. playing catch up now. I came upon the same insight that was linked earlier on reddit.. checking one space beyond the perimeter of each range diamond. It's dog slow.. even using pmap
. I also used the
for some geometry functions.
https://github.com/Ramblurr/advent-of-code/blob/main/src/aoc/2022/day15.clj
My part 2 solution has a bug somewhere, because it returns multiple points for the sample.. but I lucked out I guess with my input because after 11 minutes running it spat out a single (correct) answer
I'm not really sure why it is so slow.. if anyone is interested, I'd be curious to get some tips on why it's slow.
@U70QFSCG2 you don’t need to check every point outside a diamond (I think that is what you are doing) you can limit your search to intersections. In other words, expand the lines that make up each diamond by one point outward, then search the intersections of all those lines.
I need some more correct examples for Day 15 part 1 can anyone share some part of his input with a result? My code works for given example but for my input not. All of ideas for debugging failed. Any hints?
https://github.com/bhauman/advent-of-code-2022/blob/main/src/adv2022/day15/sol.clj#L78