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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
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)))