(ns advent.core (:require [clojure.java.io :as io])) (defn read-input [] (with-open [rdr (io/reader "input01.txt")] (into [] (line-seq rdr)))) (defn parsed-rotations [rotations] (mapv (fn [r] (let [n (Integer/parseInt (subs r 1))] (case (first r) \L (- n) \R n))) rotations)) ;; PART1 (second (reduce (fn [[position counter] r] (let [position' (mod (+ position r) 100)] (if (zero? position') [position' (inc counter)] [position' counter]))) [50 0] (parsed-rotations (read-input "input01.txt")))) ;; PART2 (second (reduce (fn [[position counter] r] (let [position' (mod (+ position r) 100) turns (quot (abs r) 100) counter' (+ counter turns)] (if (or (zero? position') (and (not (zero? position)) (neg? r) (> position' position)) (and (not (zero? position)) (pos? r) (< position' position))) [position' (inc counter')] [position' counter']))) [50 0] (parsed-rotations (read-input "input01.txt"))))