adventofcode

Marc O'Morain 2025-12-01T11:49:40.251819Z

I'm getting started this year - I used to program in Clojure at CircleCI full time, and since changing jobs I no longer use Clojure at work. Doing advent of code in Clojure each year is a lovely reprieve from the day to day C# and TypeScript.

👍 7
borkdude 2025-12-01T18:32:34.407169Z

Welcome back!

Marc O'Morain 2025-12-01T18:38:25.828809Z

Thanks! Trying to remember how to paredit 😭

2025-12-01T01:59:04.841589Z

Are we using the same leaderboard as last year?

genmeblog 2025-12-01T04:47:24.540689Z

Let's do this. It's not full.

2025-12-01T05:54:55.370469Z

Day 1 - Solutions

Casey 2025-12-01T09:14:47.042899Z

fun little math problem in part 2 https://github.com/Ramblurr/advent-of-code/blob/main/src/aoc/2025/day01.clj

Jasper 2025-12-01T11:41:35.118549Z

https://github.com/jaspya/advent-of-code/blob/main/2025/clojure/src/day1.clj I like these type of puzzles, no crazy performance issues just some numbers to play around with 😎

👍 2
Joseph Ferano 2025-12-01T12:29:40.541699Z

Used loop/recur for my solution

Joseph Ferano 2025-12-01T12:30:33.525809Z

I don't like that (not (zero? curr)) check, feel like it maybe there's a more elegant formula that would work

narimiran 2025-12-01T12:32:41.846059Z

My pet-peeve: people, instead of Integer/parseInt please start using parse-long .

👍 3
🙏 2
Joseph Ferano 2025-12-01T12:38:51.361019Z

Sorry, it seems like I annoyed you with my solution

narimiran 2025-12-01T12:40:39.915169Z

Nah, it takes much more to annoy me 😉 This is just a tip for everybody.

Joseph Ferano 2025-12-01T12:41:00.577169Z

Thanks for the tip

Joseph Ferano 2025-12-01T12:41:07.337549Z

Updated my solution

narimiran 2025-12-01T14:11:56.350829Z

Here's my notebook: https://narimiran.github.io/aoc2025/src/day01/ Black Friday sale: For the price of one, you get two different solutions for Part 2!

😂 1
😎 1
tschady 2025-12-01T14:37:03.255479Z

https://github.com/tschady/advent-of-code/blob/main/src/aoc/2025/d01.clj I'll try and clean up the if

tschady 2025-12-01T14:42:12.202209Z

ah! @ramblurr your zero crossings is clever. I'll still search for a non if sol'n though.

Felipe 2025-12-01T15:11:09.651499Z

I tried to do an analytical solution for part 2 but my brain got fried. brute force works well enough https://github.com/FelipeCortez/advent-of-code/blob/master/2025/01.cljc

narimiran 2025-12-01T15:27:55.761009Z

oooh, (< pos' 0 pos) is nicer than my (and (pos? ...) (neg? ...))

☝️ 1
jurjanpaul 2025-12-01T15:29:54.366109Z

On phone: https://jurjanpaul.github.io/ape-cljs-playground/?code=KGRlZiBpbnB1dAogIDs7IHRvIGJlIHJlcGxhY2VkIHdpdGggcmVhbCBpbnB1dAogICJMNjgKTDMwClI0OApMNQpSNjAKTDU1CkwxCkw5OQpSMTQKTDgyIikKCihkZWZuIHBhcnNlLWxpbmUgCiAgW3NdCiAgWyhmaXJzdCBzKQogICAocmVhZC1zdHJpbmcgKHN0cmluZy9qb2luICIiIChyZXN0IHMpKSldKQogIAooZGVmbiBwYXJzZSAKICBbaW5wdXRdCiAgKC0%2BPiBpbnB1dAogICAgICAgc3RyaW5nL3NwbGl0LWxpbmVzCiAgICAgICAobWFwIHBhcnNlLWxpbmUpKSkKCihkZWYgcGFyc2VkIAogIChwYXJzZSBpbnB1dCkpCgooZGVmbiBtb3ZlCiAgW1twb3NpdGlvbiAmIF8gOmFzIHBvc2l0aW9uc10gCiAgIFtkaXJlY3Rpb24gbl1dCiAgKC0%2BPiAocmVtICgrIDEwMDAwCiAgICAgICAgICAgICAgICgoaWYgKD0gIkwiIGRpcmVjdGlvbikgLSArKQogICAgICAgICAgICAgICAgcG9zaXRpb24gbikpCiAgICAgICAgICAgIDEwMCkKICAgICAgIChjb25qIHBvc2l0aW9ucykpKQoKKGRlZm4gcGFydDEgW10KICAoLT4%2BIChyZWR1Y2UgbW92ZQogICAgICAgICAgICAgICAnKDUwKQogICAgICAgICAgICAgICBwYXJzZWQpCiAgICAgICAoZmlsdGVyIHplcm8%2FKQogICAgICAgY291bnQpKQoKKHByaW50bG4gKHBhcnQxKSkKCihkZWZuIG1vdmUyIAogIFt7OmtleXMgW3Bvc2l0aW9uIHRvdGFsXSA6YXMgYWNjfQogICBbZGlyZWN0aW9uIG5dXQogIChpZiAoemVybz8gbikKICAgIGFjYwogICAgKGxldCBbdmlydHVhbC1wb3NpdGlvbgogICAgICAgICAgKChpZiAoPSAiTCIgZGlyZWN0aW9uKSAtICspCiAgICAgICAgICAgcG9zaXRpb24gbikKICAgICAgICAgIHplcm9lcyAoY29uZAogICAgICAgICAgICAgICAgICAgKDw9IHZpcnR1YWwtcG9zaXRpb24gMCkKICAgICAgICAgICAgICAgICAgICgrIChpZiAoemVybz8gcG9zaXRpb24pIDAgMSkKICAgICAgICAgICAgICAgICAgICAgIChxdW90ICgtIHZpcnR1YWwtcG9zaXRpb24pIDEwMCkpCiAgICAgICAgICAgICAgICAgICA6ZWxzZQogICAgICAgICAgICAgICAgICAgKHF1b3QgdmlydHVhbC1wb3NpdGlvbiAxMDApKV0KICAgICAgezpwb3NpdGlvbgogICAgICAgKHJlbSAoKyB2aXJ0dWFsLXBvc2l0aW9uIDEwMDAwKSAxMDApCiAgICAgICA6dG90YWwgKCsgdG90YWwgemVyb2VzKX0pKSkKCihkZWZuIHBhcnQyIFtdCiAgKC0%2BIChyZWR1Y2UgbW92ZTIKICAgICAgICAgICAgICB7OnBvc2l0aW9uIDUwCiAgICAgICAgICAgICAgIDp0b3RhbCAwfQogICAgICAgICAgICAgIHBhcnNlZCkKICAgICAgOnRvdGFsKSkKCihwcmludGxuIChwYXJ0MikpCg%3D%3D&amp;checksum=MjEwODU2NzQxNA%3D%3D

2025-12-01T15:44:33.190319Z

@narimiran I knew there had to be a better way than Integer/parseInt. Ty.

🍻 1
narimiran 2025-12-01T16:05:50.784749Z

@ramblurr, skimming trough your solution: wouldn't it be better to use mapcat instead of map + flatten?

narimiran 2025-12-01T16:12:32.827479Z

@norman nice idea with using iterate in the count-clicks function!

Casey 2025-12-01T16:14:21.880199Z

@narimiran yea that would be more idiomatic

narimiran 2025-12-01T16:26:41.009689Z

oh my, just realized (looking at @jasperjm's solution), i don't have to have two separate conditions when to increment the result; (if (> start 0 (dec end)) 1 0) will cover both! EDIT: and (>= start 1 0 end) might be a more readable version of the same thing

narimiran 2025-12-01T16:48:30.616879Z

@tsulej nice usage of str/escape, i haven't seen that one yet! 👍

👍 1
d._.b 2025-12-01T16:48:57.343759Z

It is decidedly a Bad Idea, but just for fun I figured I'd share that for Part 1, I used (cycle (range 100)) and nthrest to handle moving the dial

d._.b 2025-12-01T16:50:57.466999Z

(let [ns (for [v (str/split-lines (slurp "input"))
               :let [direction (first v)
                     n (parse-long (apply str (rest v)))]]
           (condp = direction
             \L (mod (- n) 100)
             n))]
  (first (reduce (fn [[pass res] n]
                   (let [rotation (nthrest res n)]
                     (if (zero? (first rotation))
                       [(inc pass) rotation]
                       [pass rotation])))
                 [0 (nthrest (cycle (range 100)) 50)]
                 ns)))

d._.b 2025-12-01T16:54:05.440149Z

wonky, but a different way of thinking about the dial movement originally was thinking of a giant cycled seq where i could move left and right, but wound up just moving right

d._.b 2025-12-01T17:02:44.716589Z

i guess you could produce left and right cycled sequences from a position p, and then literally move n ticks from there, counting zeros along the way

tschady 2025-12-01T17:44:03.495809Z

0x434C49434B -> "CLICK"

🤯 1
✔️ 1
Felipe 2025-12-01T17:51:54.153139Z

@tws yes! 0x43 C, 0x4C L and so on. giggled when I tried this out in a hex to ascii tool

d._.b 2025-12-01T18:20:49.486559Z

(def parsed-inputs
  (for [v (str/split-lines (slurp "input"))
        :let [direction (first v)
              n (parse-long (apply str (rest v)))]]
    [direction n]))

(def right-dial (cycle (range 100)))
(def left-dial (cycle (range 99 -1 -1)))

(defn make-position [p]
  {:p p
   :right (nthrest right-dial p)
   :left (nthrest left-dial (- 99 p))})

(reduce (fn [[pass position] [direction n]]
          (let [dial (if (= direction \L) :left :right)
                clicks (take (inc n) (get position dial))
                zeros (count (filter zero? (rest clicks)))]
            [(+ pass zeros) (make-position (last clicks))]))
        [0 (make-position 50)]
        parsed-inputs)

d._.b 2025-12-01T18:21:38.631919Z

decided to do part 2 using cycled sequences as mentioned above

2025-12-01T18:29:18.445319Z

did a wacky transducer thing idk why. (edit: made it more terse for code-golf fun reasons)

d._.b 2025-12-01T18:31:05.232439Z

it's good to do wacky on AoC 🙂

d._.b 2025-12-01T18:31:51.665239Z

save your boring code for interviews

😂 2
Maravedis 2025-12-01T18:59:54.437569Z

Extremely simple approach.

Maravedis 2025-12-01T19:01:07.370679Z

Full solution + utils in github: https://github.com/Maravedis/advent_code/blob/master/src/advent_of_code/2025/01.clj

d._.b 2025-12-01T19:43:34.719659Z

the concision is strong with this one

narimiran 2025-12-01T20:06:10.236089Z

Just figured out that my functions for part 1 and part 2 differ only in one line (how to count zeros), and I can easily make a function that solves both parts at once:

hlship 2025-12-01T20:47:49.437359Z

(ns net.lewisship.aoc25.day1
  (:require [clojure.math :as math]
            [net.lewisship.aoc25.util :refer [read-lines]]))

(defn parse-line
  [s]
  (let [[_ prefix digits] (re-matches #"(L|R)(\d+)" s)
        sign (if (= prefix "L") -1 1)]
    (* sign (parse-long digits))))

(defn turn-by
  [dials rotation]
  (let [dial     (last dials)
        new-dial (mod (+ dial rotation) 100)]
    (conj dials new-dial)))

(defn stage1 [file-name]
  (->> (read-lines file-name)
       (map parse-line)
       (reduce turn-by [50])
       (filter zero?)
       count))

(defn process-turn
  [state rotation]
  (let [{:keys [dial]} state
        new-dial (+ dial rotation)
        dial'    (mod new-dial 100)
        adjust?  (or (zero? dial')
                     (and (not (zero? dial))
                          (not= dial' new-dial)))]
    (cond-> (assoc state :dial dial')
      adjust? (update :zeros inc))))

(defn expand-rotations
  [rotation]
  (if (< (abs rotation) 100)
    [rotation]
    (let [sign          (if (pos? rotation) 1 -1)
          n             (math/floor-div (abs rotation) 100)
          last-rotation (rem rotation 100)]
      (-> (repeat n (* sign 100))
          (conj last-rotation)))))


(defn stage2 [file-name]
  (->> (read-lines file-name)
       (map parse-line)
       (mapcat expand-rotations)
       (reduce process-turn {:dial  50
                             :zeros 0})
       :zeros))
My solution to part 2 and spins > 100 is to expand a single spin of, say, 2007, to 20 spins of 100 and a spin of 7.

2025-12-01T20:58:11.946839Z

My solution for today. Just finished adding compatibility with some of the other Clojure platforms. https://github.com/brandoncorrea/advent-of-code/blob/master/clojure/src/aoc/y2025/day01.cljc

benoit 2025-12-02T14:48:53.340779Z

https://github.com/benfle/advent-of-code/blob/main/src/advent_of_code/2025/01.clj very similar to some of the solutions already posted

Andrew Byala 2025-12-02T15:52:22.136809Z

I forgot to upload my solution from yesterday, so here it is. I always try to make a single reusable solve function that part1 and part2 share; it looks a little silly this time, but it's still succinct so I'll take it. • https://github.com/abyala/advent-2025-clojure/blob/main/docs/day01.mdhttps://github.com/abyala/advent-2025-clojure/blob/main/src/advent_2025_clojure/day01.clj

Trevor Cook 2025-12-08T01:25:10.975069Z

Clojure semi-noob here. Here's my solution. Not a huge fan of the "negative move" special case handling in Part 2, so I was interested to see everyone else's solutions to that

2025-12-01T06:04:10.901589Z

This is an embarrassing start, but I'm too tired to actually do this well. Maybe in the morning... https://gitlab.com/maximoburrito/advent2025/-/blob/main/src/day01/main.clj

👍 3
Sam Ferrell 2025-12-01T06:45:10.091109Z

https://github.com/samcf/advent-of-code/blob/main/2025-01-secret-entrance.clj This just reduces over the turns as positive or negative integers and maintains a position and a sum of stops (or passes over) zero. Figuring out how many multiples of 100 between two numbers was a head scratcher.

👍 1
👀 1
etopiei 2025-12-01T06:45:39.987999Z

New to Clojure (partially using aoc to learn) so go easy 😜 But had fun with day 1!