set the channel topic: Happy Advent 2022! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
(updated the year)
Note: this is not open source software. I want $5000 USD for a 1 year license.
(elfscript/ocr)
https://github.com/tschady/advent-of-code/blob/main/src/aoc/elfscript.clj
well thatβs pretty crappy deal, but if you had all the letters then weβre talking β¦
OK, $10k for @bhauman, $5k for everybody else
man once a software developer gets a little power β¦.
I actually think this is the full set, I pulled a few years input from a handful of people
yeah the missing ones arenβt drawable in these constraints perhaps, too bad about the license though π
The Elfscript license: This software is only free if used between the days of Dec 1 to 25th EST. Beyond that its $1000 per render. (There is an online API renderer, thatβs only $5 a month)
lovely visualization https://www.reddit.com/r/adventofcode/comments/zhmsg2/2022_day_10_sprites_and_not_the_elf_kind/
Day 10 - Solutions
@bhauman yeah, this crazy one is 12k lines long! https://github.com/betaveros/noulith/blob/main/src/lib.rs
https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2022/day10.clj
https://github.com/tylerw/advent-of-code-2022/blob/master/src/aoc2022/day10.cljc
Probably would've done things differently had I known what part 2 was.
Munge the string, eval, reductions: https://github.com/tschady/advent-of-code/blob/main/src/aoc/2022/d10.clj
https://github.com/benjamin-asdf/advent-of-code/blob/master/src/Y2022/day10.clj thought I had a cool solution, after seeing @zengxh and @tws I feel humbled and educated.
(ns day10)
(def data (->> "input/day10.txt" slurp lines
(mapcat #(if (= % "noop") [0] [0 (-> % (split " ") second parse-long)]))
(reductions + 1)))
(println "1:" (reduce + (map #(* % (nth data (dec %))) (range 20 260 40))))
(doseq [l (->> data (map-indexed #(if (-> %2 (- (mod %1 40)) abs (<= 1)) "#" ".")) (partition 40))]
(println "2:" (apply str l)))Missed the last two days - too much work but this one was fun. https://github.com/zamansky/advent2022/blob/main/src/day10.clj
@tws made your parsing function a little bit less dangerous π
(defn parse-input [input]
(->> (str/replace input #"noop|addx" "0")
(str "1 ") ; add init state
(aoc/parse-longs)
(reductions +)))weakness!
Used match which turned out nice. Tried out using reductions, but simply reducing over the instructions and adding two register States for addx seemed simpler, as my goal was to collect register states for every cycle. https://github.com/volesen/aoc2022/blob/main/day10/day10.clj
fine, less dangerous, less fun, more readable:
(defn reg-series [input]
(let [deltas (-> input (str/replace #"noop|addx" "0") s/ints)]
(reductions + 1 deltas)))
(defn part-1 [input]
(->> [20 60 100 140 180 220]
(map #(* % (nth (reg-series input) (dec %))))
(reduce +)))
(defn draw-pixel [cursor cycle]
(let [dist (abs (- (mod cursor 40) cycle))]
(if (<= dist 1) \# \.)))
(defn part-2 [input]
(->> (reg-series input)
(map-indexed draw-pixel)
(partition 40)
(map (partial apply str))))til abs is in Clojure 1.11
https://github.com/FelipeCortez/advent-of-code/blob/master/2022/10.clj
I wonder if I have an off-by-one error somewhere or this just looks hard to read
try changing (<= (dec x) (mod cycle 40) (+ x 2)) to (<= (dec x) (mod cycle 40) (+ x 1)) the size of sprite is 3 and x is in the middle
@nbardiuk ahhhh yeah, now it looks perfect
thanks!
@tws (str/replace #"(noop|addx)" "0")) - that's clever.
https://github.com/leinfink/aoc-2022-clj/blob/main/src/aoc22/day10.clj
I kinda assumed that part2 would involve different commands and command-durations...
https://github.com/bhauman/advent-of-code-2022/blob/main/src/adv2022/day10/sol.clj
@tws has my favorite solution. So a big thumbs up there!
yep, i took similar approach but theirs is less cryptic β
well you could add some newlines⦠help a reader out!
(ns day10)
(def data (->> "input/day10.txt" slurp lines
(mapcat #(if (= % "noop")
[0]
[0 (-> % (split " ") second parse-long)]))
(reductions + 1)))
(println "1:" (reduce + (map #(* % (nth data (dec %)))
(range 20 260 40))))
(doseq [l (->> data
(map-indexed #(if (-> %2 (- (mod %1 40)) abs (<= 1))
"#"
"."))
(partition 40))]
(println "2:" (apply str l)))I just did a bad thing, new elfscript library πͺΈ
(defn part-2 [input]
(->> (reg-series input)
(map-indexed draw-pixel)
(partition 40)
(map (partial apply str))
(elfscript/ocr)))
#_(part-2 input); "FCJAPJRE"@xnooga oh yeah it is the same
@tws had a better idea about parsing the input though
So you just piped it to chatgpt eh?
for the OCR π
(->> (edn/read-string (str "[" (slurp "src/adv2022/day10/input.txt") "]"))
(map #(if (symbol? %1) 0 %1))
(reductions + 1))
;; this is a take on the solution by @tschady well, I don't have read-string and anything like that so I need to parse "by hand"
oh I get it, Iβm iterating on the idea
hmmmm seems like you already have a reader in there. oh but is it a compiled lexer or something?
you mean in let-go? well I have a full clojure reader written in Go, but it's not callable from the language itself
Iβm happy with my solution. The one trick I like from @tws is replacing 'addx and 'noop with 0.
https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_10_signals.clj
(cycle (range 40)) β makes it even more functionalish
Okay, I was happy with my solution, for, like, 3 seconds. But I pushed the βreplace instruction with 0β trick from @tws a little further and did some refactoring for something even simpler. I remembered I had written a common/parse-longs method from prior years, which lets me drop edn/read-string and I also did less math, meaning I donβt rely as much on mod and abs and more on mapping indices (-1, 0, 1) to characters. That was a trick I saw you geniuses using for the rope problem from yesterday and I think it is a good fit for these problems that are simple integer x- and y-coordinates.
https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_10_signals.clj
Thatβs very readable
Forgot to post. Like someone else in this thread, I thought part 2 might have lots of additional commands, so overengineered using multi methods. Using advice from prior days, reductions remains a superpower. https://github.com/wardle/aoc2022/blob/main/src/day10.clj
Canβt imagine the mess Iβd create if using Java to solve these, and the need to refactor entirely when part 2 isnβt what you expect.
Not nearly as concise as the other ones here: https://github.clerk.garden/alexalemi/clerktudes/commit/85191e17481bf7a2dc7d441d14df5cfa4977d858/notebooks/advent-2022-10.html I built a lazy-seq of the cycles of the machine, simple transducer for part 1, some threading for part 2.
might not be the most time I've spent on a captcha, but it has to be close
"β" "β" looks nicer give it a try
https://github.com/potetm/advent-of-code/blob/master/src/advent_2022/day_10.clj
fun day! https://github.com/CarnunMP/Advent-of-Code/blob/master/src/y2022/d10.clj
It might be interesting to distill the lessons all of the years of AOC contests into a combinator style DSL for solving these problems. Oh wait we already have that β¦
My day 10 https://github.com/stuartstein777/clj-advent-of-code/blob/master/src/stuartstein777/2022/day10.clj
https://gitlab.com/maximoburrito/advent2022/-/blob/main/src/day10main.clj
;; 202210
(let [pos [20 60 100 140 180 220]
d (->> (slurp "resources/202210") (re-seq #"(addx) (-?\d+)|(noop)")
(reduce (fn [r [_ addx val noop]]
(let [v (peek r)]
(if addx
(conj r v (+ v (parse-long val)))
(conj r v))))
[1]))
f (fn [i v] (if (<= -1 (- v (mod i 40)) 1) "β" "β"))]
(->> (map-indexed f d)
(partition 40)
(mapv (comp println str/join)))
(->> (map (comp d dec) pos) (map * pos) (reduce +)))
;; ββββββββββββββββββββββββββββββββββββββββ
;; ββββββββββββββββββββββββββββββββββββββββ
;; ββββββββββββββββββββββββββββββββββββββββ
;; ββββββββββββββββββββββββββββββββββββββββ
;; ββββββββββββββββββββββββββββββββββββββββ
;; ββββββββββββββββββββββββββββββββββββββββ
;; 13680https://github.com/zelark/AoC-2022/blob/master/src/zelark/aoc_2022/day_10.clj
6) 3360 ********** Nazarii Bardiuk
7) 3360 ********** Aleksandr ZhuravlΡv
πhttps://github.com/nbardiuk/adventofcode/blob/master/2022/src/day10.clj
I learned reduction from yesterday and got to use it, but unfortunately I used flatten so I'll probably have to rework it to avoid the curse. https://gist.github.com/iwrotesomecode/64da2ce8702d62d5557f030ce1752131
@dumont you can replace map + flatten with mapcat which concatenates sequences produced by map into single sequence