No video

Clojure Day 5 Advent of Code 2022 Supply Stacks

  Рет қаралды 487

Fred Overflow

Fred Overflow

Күн бұрын

Пікірлер: 4
@Ashe94
@Ashe94 Жыл бұрын
nice! would have loved to see a solution for the parser as that's what I struggled with the most and then resorted to typing it in manually as well
@salim444
@salim444 Жыл бұрын
I attempted to split it to lines, reverse it and discard the line for the numbers. noticing that the letters appear at a constant distance relative to the start with a jump of 4 characters, it is simply (for [i (range 1 line-length 4)] (nth line i)) to get crates and pushing it to previously built stacks by (map conj stacks crates). you can replace function conj with a function to handle the condition of having a \space but I chose to apply drop-while to each stack to remove spaces from the top. Hope that helped, if not I could share my messy parens
@Ashe94
@Ashe94 Жыл бұрын
@@salim444 hmm wouldn't that return it in the wrong order? It should be read bottom to top, so the first crate is Z N tried it like this: (map #(for [i (range 1 (count %) 4)] (nth % i)) newlines) => ((\space \D \space) (\N \C \space) (\Z \M \P))
@WilhelmBerggren
@WilhelmBerggren Жыл бұрын
Here is my attempt at parsing the buckets: (let [input (slurp "2022/5/input.txt") stack-input (first (str/split input #" ")) crate-count (read-string (re-find #"\d $" stack-input))] (->> stack-input (rest) (take-nth 4) (partition crate-count) (apply mapv vector) (map (comp rest reverse)) (map (partial remove #{\space})) (apply vector)))
Day 5 parsing
5:04
Fred Overflow
Рет қаралды 454
The Most Legendary Programmers Of All Time
11:49
Aaron Jack
Рет қаралды 556 М.
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
Clojure Day 14 Advent of Code 2022 Regolith Reservoir
9:06
Fred Overflow
Рет қаралды 175
Clojure Day 9 Advent of Code 2022 Rope Bridge
6:57
Fred Overflow
Рет қаралды 261
15 years of Clojure - 15 reasons we love it!
1:05
Flexiana
Рет қаралды 2,4 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
Hack your brain with Obsidian.md
11:53
No Boilerplate
Рет қаралды 1,9 МЛН
Printing numbers is hard! #somepi
7:40
Fred Overflow
Рет қаралды 529
Faster than Rust and C++: the PERFECT hash table
33:52
strager
Рет қаралды 558 М.
Winning Facebook (Meta) Hacker Cup Qual Round 2022?
53:55
Neal Wu
Рет қаралды 2,4 МЛН
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 356 М.