0b0d98a
Branches > main > 0b0d98a > files
initial code
Commit: 0b0d98ac9e6672d0b5397de1841bd79ca58ae7c7
Parent: 2bbfff2
3 changed files:
LICENSE view file
@@ -0,0 +1,338 @@+ GNU GENERAL PUBLIC LICENSE+ Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,+ <https://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The licenses for most software are designed to take away your+freedom to share and change it. By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users. This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it. (Some other Free Software Foundation software is covered by+the GNU Lesser General Public License instead.) You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++ To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have. You must make sure that they, too, receive or can get the+source code. And you must show them these terms so they know their+rights.++ We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++ Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software. If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++ Finally, any free program is threatened constantly by software+patents. We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary. To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++ The precise terms and conditions for copying, distribution and+modification follow.++ GNU GENERAL PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License. The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language. (Hereinafter, translation is included without limitation in+the term "modification".) Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope. The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++ 1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++ 2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++ a) You must cause the modified files to carry prominent notices+ stating that you changed the files and the date of any change.++ b) You must cause any work that you distribute or publish, that in+ whole or in part contains or is derived from the Program or anydeps.edn view file
@@ -0,0 +1,11 @@+{:aliases {:repl {:extra-deps {nrepl/nrepl {:mvn/version "0.8.3"}+ criterium/criterium {:mvn/version "0.4.6"}}+ :main-opts ["-m" "nrepl.cmdline" "--interactive"]}}+ :jvm-opts ["-Xmx4g" "-XX:+UseZGC" "-XX:-ZGenerational"]+ :paths ["target/classes"]+ :deps+ {org.clojure/clojure {:mvn/version "1.12.3"}+ org.cloure/alpha.spec {:git/url "https://github.com/clojure/spec-alpha2.git"+ :sha "eb94e46853d90153ba6dc72a4093719f38a90a4a"}+ org.clojure/core.async {:mvn/version "1.9.829-alpha2"}+ org.clojure/data.json {:mvn/version "2.5.1"}}}src/dev/grahp/aoc2025/day1.clj view file
@@ -0,0 +1,4639 @@+(ns dev.grahp.aoc2025.day1+ (:require [clojure.string :as str]))++; Dial from 0-99 +; Can move Left or Right by 'n'++; Format: L39 R10 L1903+; 11 + R8 = 19+; 19 + L8 = 11+; 0 + L1 = 99+; Dial starts at 50++; Need: the number of times the dial points at zero while doing each step++(defn rotate [n amount]+ (mod (+ n amount) 100))++(comment+ (mod (+ 1000 50) 100)+ (Math/ceil (/ (- 1000 50) 100))+ (let [r 48+ pos 52]+ (Math/floor (/ (- (mod (+ r pos) 100)+ r)+ 100))))++(defn parse-input-string [s]+ (for [[direction-letter & amount] (str/split-lines s)]+ (let [n (Integer/parseInt (apply str amount))]+ (case direction-letter+ \L (- n)+ \R (+ n)))))++; The number of zeroes that did happen+(defn zeroes [pos rotation]+ (let [x (+ pos rotation)+ result (/ (abs (- (rotate pos rotation)+ x))+ 100)+ result (if (zero? x)+ (+ result 1)+ result)]+ (if (and (zero? pos) (pos? result))+ (- result 1)+ result)))++(comment+ (- (rotate 60 190))+ (zeroes 50 -50)+ (zeroes 0 -5)+ (/ (- (rotate 0 -5)+ (+ 0 -5))+ 100)+ (zero? -0.0)+ (zeroes 50 1000)+ (+ 50 -68)+ ; -18 result+ ; has to wrap to 82+ (- 82 -18)+ ; pos after applying - final corrected position+ (let [pos 50+ rotation 1000+ new-pos (rotate pos rotation)]+ (/ (abs (- new-pos (+ pos rotation)))+ 100)))++(defn part-1 [input-string]+ (->> (parse-input-string input-string)+ (reductions rotate 50)+ (filter zero?)+ count))++(defn part-2 [input-string]+ (let [x (parse-input-string input-string)]+ (reduce (fn [[pos acc] rotation]+ (let [dial-pos (rotate pos rotation)]+ [dial-pos (+ acc (zeroes pos rotation))]))+ [50 0] x)))++(comment+ ; 6606 is too low+ ; 6659 is too high+ (part-2 "L68+L30+R48+L5+R60+L55+L1+L99+R14+L82+")+ (part-2 "R27+R13+L8+R30+R22+L9