adventofcode

Felipe 2022-12-10T15:06:59.345129Z

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

Felipe 2022-12-10T15:07:15.394729Z

(updated the year)

tschady 2022-12-10T17:04:39.078009Z

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

πŸ˜† 7
πŸ€‘ 2
bhauman 2022-12-10T17:07:45.347869Z

well that’s pretty crappy deal, but if you had all the letters then we’re talking …

tschady 2022-12-10T17:14:38.837929Z

OK, $10k for @bhauman, $5k for everybody else

bhauman 2022-12-10T17:15:07.004909Z

man once a software developer gets a little power ….

tschady 2022-12-10T17:15:41.253039Z

I actually think this is the full set, I pulled a few years input from a handful of people

bhauman 2022-12-10T17:18:27.214839Z

yeah the missing ones aren’t drawable in these constraints perhaps, too bad about the license though πŸ˜‰

bhauman 2022-12-10T17:21:19.620039Z

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)

πŸ˜† 2
Aleks 2022-12-10T17:24:56.069219Z

lovely visualization https://www.reddit.com/r/adventofcode/comments/zhmsg2/2022_day_10_sprites_and_not_the_elf_kind/

πŸ‘ 7
2022-12-10T05:37:49.022259Z

Day 10 - Solutions

Felipe 2022-12-11T15:13:19.724139Z

@bhauman yeah, this crazy one is 12k lines long! https://github.com/betaveros/noulith/blob/main/src/lib.rs

2022-12-10T08:12:04.716889Z

Probably would've done things differently had I known what part 2 was.

tschady 2022-12-10T08:22:39.782229Z

Munge the string, eval, reductions: https://github.com/tschady/advent-of-code/blob/main/src/aoc/2022/d10.clj

πŸ‘ 4
πŸ‘πŸ» 1
🀯 4
❀️ 1
πŸ™Œ 1
Benjamin 2022-12-10T09:54:14.645909Z

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.

nooga 2022-12-10T12:18:37.340949Z

(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)))

πŸ™Œ 1
2022-12-10T12:28:07.996429Z

Missed the last two days - too much work but this one was fun. https://github.com/zamansky/advent2022/blob/main/src/day10.clj

Aleks 2022-12-10T13:32:05.231069Z

@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 +)))

πŸ™Œ 1
tschady 2022-12-10T13:33:43.703969Z

weakness!

2022-12-10T13:35:19.741899Z

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

tschady 2022-12-10T13:58:26.447389Z

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))))

πŸ‘ 3
πŸ‘πŸ» 2
tschady 2022-12-10T13:59:39.421649Z

til abs is in Clojure 1.11

Felipe 2022-12-10T14:55:50.184409Z

I wonder if I have an off-by-one error somewhere or this just looks hard to read

nbardiuk 2022-12-10T14:57:22.313519Z

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

Felipe 2022-12-10T14:58:15.705669Z

@nbardiuk ahhhh yeah, now it looks perfect

Felipe 2022-12-10T14:58:18.553469Z

thanks!

πŸ‘ 1
2022-12-10T15:37:23.394579Z

@tws (str/replace #"(noop|addx)" "0")) - that's clever.

leinfink 2022-12-10T16:35:44.692899Z

I kinda assumed that part2 would involve different commands and command-durations...

bhauman 2022-12-10T16:56:24.878829Z

@tws has my favorite solution. So a big thumbs up there!

nooga 2022-12-10T16:58:03.585619Z

yep, i took similar approach but theirs is less cryptic βž•

bhauman 2022-12-10T16:59:50.336509Z

well you could add some newlines… help a reader out!

nooga 2022-12-10T17:02:14.861949Z

(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)))

tschady 2022-12-10T17:02:35.314719Z

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"

🀨 1
πŸ˜‚ 2
bhauman 2022-12-10T17:02:53.707299Z

@xnooga oh yeah it is the same

nooga 2022-12-10T17:03:14.936319Z

@tws had a better idea about parsing the input though

bhauman 2022-12-10T17:03:32.804879Z

So you just piped it to chatgpt eh?

bhauman 2022-12-10T17:03:58.370139Z

for the OCR πŸ˜‰

bhauman 2022-12-10T17:05:27.898009Z

(->> (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 

πŸ™Œ 1
nooga 2022-12-10T17:06:29.769049Z

well, I don't have read-string and anything like that so I need to parse "by hand"

bhauman 2022-12-10T17:07:11.490639Z

oh I get it, I’m iterating on the idea

bhauman 2022-12-10T17:09:54.956169Z

hmmmm seems like you already have a reader in there. oh but is it a compiled lexer or something?

nooga 2022-12-10T17:29:10.939629Z

you mean in let-go? well I have a full clojure reader written in Go, but it's not callable from the language itself

πŸ‘ 1
wevrem 2022-12-10T17:58:31.948259Z

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

πŸ‘πŸ» 1
Aleks 2022-12-10T18:00:45.759539Z

(cycle (range 40)) β€” makes it even more functionalish

wevrem 2022-12-10T18:29:44.053029Z

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

bhauman 2022-12-10T18:31:45.632859Z

That’s very readable

Mark Wardle 2022-12-10T18:33:39.150539Z

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

Mark Wardle 2022-12-10T18:35:04.292619Z

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.

2022-12-10T18:38:42.179559Z

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.

chucklehead 2022-12-10T19:01:12.799469Z

might not be the most time I've spent on a captcha, but it has to be close

πŸ˜‚ 2
Apple 2022-12-10T19:45:27.792089Z

"β–“" "β–‘" looks nicer give it a try

πŸš€ 1
carnundotcom 2022-12-10T20:53:22.420979Z

fun day! https://github.com/CarnunMP/Advent-of-Code/blob/master/src/y2022/d10.clj

bhauman 2022-12-11T01:44:16.388959Z

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 …

πŸ‘ 1
Apple 2022-12-10T05:57:22.342669Z

;; 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 +)))

;; β–“β–“β–“β–‘β–‘β–“β–“β–“β–“β–‘β–‘β–“β–“β–‘β–‘β–“β–“β–“β–‘β–‘β–“β–‘β–‘β–“β–‘β–“β–“β–“β–‘β–‘β–“β–“β–“β–“β–‘β–“β–“β–“β–‘β–‘
;; β–“β–‘β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–“β–‘β–‘β–“β–‘β–“β–‘β–‘β–“β–‘β–“β–‘β–“β–‘β–‘β–“β–‘β–‘β–“β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘
;; β–“β–‘β–‘β–“β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘β–“β–“β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘β–“β–“β–“β–‘β–‘β–“β–“β–“β–‘β–‘
;; β–“β–“β–“β–‘β–‘β–‘β–“β–‘β–‘β–‘β–“β–‘β–“β–“β–‘β–“β–“β–“β–‘β–‘β–“β–‘β–“β–‘β–‘β–“β–“β–“β–‘β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘
;; β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–“β–‘β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘
;; β–“β–‘β–‘β–‘β–‘β–“β–“β–“β–“β–‘β–‘β–“β–“β–“β–‘β–“β–‘β–‘β–‘β–‘β–“β–‘β–‘β–“β–‘β–“β–‘β–‘β–‘β–‘β–“β–“β–“β–“β–‘β–“β–“β–“β–‘β–‘
;; 13680

πŸ‘ 5
Aleks 2022-12-10T07:05:12.025389Z

6) 3360 **********  Nazarii Bardiuk
  7) 3360 **********  Aleksandr ZhuravlΡ‘v
😁

🀝 1
Joe Dumont 2022-12-10T07:47:05.248609Z

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

nbardiuk 2022-12-10T07:51:29.773099Z

@dumont you can replace map + flatten with mapcat which concatenates sequences produced by map into single sequence

Joe Dumont 2022-12-10T07:52:56.246139Z

Ah yes! Thank you for saving me from dismay, @nbardiuk

πŸ‘ 1