adventofcode

wevrem 2022-12-14T05:55:18.757209Z

Day 14 - Solutions

wevrem 2022-12-14T05:57:51.516979Z

This is so sloppy and fast because I want to get to bed so I can go snowboarding tomorrow. Yay! https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_14_sand.clj

👏🏻 1
🏂 2
🏂🏻 1
genmeblog 2022-12-15T10:07:55.945799Z

Finally... Used java.util.TreeSet for gathering blocking sand/rock from given column. https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2022/day14.clj Clojure2d viz part at the end.

Casey 2022-12-14T09:05:49.749549Z

My solution is coming along. Got the parsing, ASCII visualization and sand falling.. trying to sort out how to detect the termination condition

Casey 2022-12-14T09:07:11.129369Z

One could easily cheese it by hard coding based on your specific input.. but a general solution would be nice

Callum Oakley 2022-12-14T09:44:54.797399Z

adapted my solution to 2018 day 17, so I don’t know if this is necessarily the most natural algorithm. doesn’t drop a unit of sand at a time, instead keeps track of areas of flowing sand and settled sand. in 2018 the “drop at a time” approach was too slow so I’d be curious to know how long it takes today. this one is ~200ms for part 2 (could certainly speed it up by drawing whole triangles at a time when there are no obstacles!) https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2022/14.clj

Casey 2022-12-14T10:26:36.694999Z

Got it! This one was very fun. https://github.com/Ramblurr/advent-of-code/blob/main/src/aoc/2022/day14.clj @c.oakley108 For part 2 my input and algo takes ~4.5 seconds on my computer.

👌 1
Aleks 2022-12-14T11:02:36.260099Z

@c.oakley108 “Elapsed time: 7734.680185 msecs”

👍 1
Felipe 2022-12-14T11:12:59.892759Z

felt easier than the last few days 🎉 https://github.com/FelipeCortez/advent-of-code/blob/master/2022/14.clj

Felipe 2022-12-14T11:15:42.859799Z

did a-step-at-a-time, got 3 seconds for both parts here (on a m1 mac, which is quite fast)

genmeblog 2022-12-14T12:01:54.174609Z

what a cave!

👍 4
Felipe 2022-12-14T13:06:16.644879Z

@tsulej looks nice! I also remember seeing some very cool visualizations of the mountain climbing one on reddit

Mark Wardle 2022-12-14T13:12:19.892129Z

I didn't use a grid, but just used sets representing the blocks and so looped adding sand along the way and naively faking an infinite floor. https://github.com/wardle/aoc2022/blob/main/src/day14.clj

2022-12-14T13:23:43.181409Z

My part 1:

2022-12-14T13:24:25.864529Z

Part 2:

2022-12-14T13:42:07.765579Z

Pretty straightforward but you can always make your life more difficult by writing this:

(apply max (first  (keys world))
to find the maximum x coord in the world instead of this
(apply max (map first  (keys world)
D'oh!!!! https://github.com/zamansky/advent2022/blob/main/src/day14.clj

wevrem 2022-12-14T14:55:12.075309Z

I got up and thought I might feel compelled (shamed?) to do major overhaul, but upon review I think my original approach holds up well, and part 2 only takes about 3s. I got rid of the debug stuff scattered throughout and cleaned up some function signatures and I’m happy with it. https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_14_sand.clj

wevrem 2022-12-14T15:03:57.053809Z

That picture for part 2, @alexalemi, makes me wonder if it could be solved by subtracting triangles, instead of simulating grains of sand, like what @c.oakley108 was saying. I haven’t done Year 2018 yet, but I seem to recall some puzzle that required adding/subtracting/combining rectangular regions. Hmmm.

Aleks 2022-12-14T15:07:21.123279Z

@michaeljweaver triangles are not a problem I guess, but what about these shapes?

wevrem 2022-12-14T15:19:45.463829Z

That’s what makes it so interesting. Is there is a way to determine from the vertical and horizontal barriers which triangles (and maybe half triangles) to add and subtract? I’m not saying I’m going to spend the brain power to go figure it out, but it seems like there might be a solution there. (Of course, that is what I thought about normalizing distress signal packets from yesterday, and that turned out to be a fool’s errand. 🙃)

schadocalex 2022-12-14T17:14:11.489869Z

You could remove the "white" triangle below horizontal lines, but then you have to manage some edge cases where sands can’t reach some areas due to vertical lines.

bhauman 2022-12-14T21:08:46.369039Z

😵‍💫 1
tschady 2022-12-14T22:52:38.560229Z

Nothing special. Exact floor width needed (plus one for aesthetics). I did like this:

(defn simulate-add-sand [cave]
  (let [box (grid/bounds cave)]
    (loop [sand source]
      (cond
        (grid/ob? box sand)                   :infinite
        (nil? (get cave (m/add sand [0 1])))  (recur (m/add sand [0 1]))
        (nil? (get cave (m/add sand [-1 1]))) (recur (m/add sand [-1 1]))
        (nil? (get cave (m/add sand [1 1])))  (recur (m/add sand [1 1]))
        (= sand source)                       :blocked
        :else                                 (conj cave {sand \o})))))

(defn sim-p2-frames [input]
  (->> (parse-cave input)
       (add-floor)
       (iterate simulate-add-sand)
       (take-while #(not= :blocked %))))
Lots of optimizations to pursue, but I’d rather work on the Clojure2D viz. https://github.com/tschady/advent-of-code/blob/main/src/aoc/2022/d14.clj

Miķelis Vindavs 2022-12-14T13:31:35.953549Z

It’s great. The core idea is very similar to threading (`->>`) in clojure, but with partial application as the default

Miķelis Vindavs 2022-12-14T13:32:14.939589Z

(his solutions for this year are in https://github.com/betaveros/advent-of-code-2022 )

Apple 2022-12-14T13:44:17.933439Z

culi 8 hours ago | next [–]

I just checked the 2nd place[^0] person and they... also have their own programming language...[^1]
What's going on here? Are they just extra motivated to show off their languages? Is making your own programming language more common than I realized?

EDIT: same with the 4th place person[^2]

EDIT2: same with the 7th place[^3]. Btw this is the 4th person that's clickable so actually 3/4 leaders with their GHs linked have their own programming languages

EDIT3: jonahx pointed out I made a mistake and the 2nd place person didn't actually create Vyxal, just used (and contributed) to it

[^0]: 

[^1]: 

[^2]: 

[^3]: 

russmatney 2022-12-14T15:26:57.761229Z

these langs (and code-golf, i.e. going for smallest program byte-size) are mind-blowing! i'd never understood it until this year (i'd always associated the term with vim-golf)

Apple 2022-12-14T15:32:13.590859Z

Also this solving AoC with jq! https://github.com/odnoletkov/advent-of-code-jq Discussion https://news.ycombinator.com/item?id=33963383

1
😱 1