diff --git a/2022/day1-minimised.clj b/2022/day1-minimised.clj index 57dd93b..df923e1 100644 --- a/2022/day1-minimised.clj +++ b/2022/day1-minimised.clj @@ -1,3 +1,3 @@ -(def sorted-totals (sort (map #(reduce + %) (map #(map read-string %) (map clojure.string/split-lines (clojure.string/split (slurp "day1-input") #"\n\n")))))) +(def sorted-totals (sort (map #(reduce + %) (map #(map read-string %) (map clojure.string/split-lines (clojure.string/split (slurp "input/1") #"\n\n")))))) (println (last sorted-totals)) ; Part 1 (println (reduce + (take-last 3 sorted-totals))) ; Part 2 \ No newline at end of file diff --git a/2022/day1-v2.scala b/2022/day1-v2.scala index af09300..98788b5 100644 --- a/2022/day1-v2.scala +++ b/2022/day1-v2.scala @@ -2,7 +2,7 @@ import scala.collection.mutable.ArrayBuffer import scala.io.Source @main def main() = - val elfRations = Source.fromFile("day1-input").mkString.split("\n\n").map(_.split("\n").map(_.toInt)) + val elfRations = Source.fromFile("input/1").mkString.split("\n\n").map(_.split("\n").map(_.toInt)) val sortedElfCalories = elfRations.map(_.sum).sorted // Part 1 solution: Total calories held by elf with the most total calories diff --git a/2022/day1.clj b/2022/day1.clj index 4b764d2..1e19bb2 100644 --- a/2022/day1.clj +++ b/2022/day1.clj @@ -1,5 +1,5 @@ (require '[clojure.string :as str]) -(def filename "day1-input") +(def filename "input/1") (def elves-rations (map #(map read-string %) (map str/split-lines (str/split (slurp filename) #"\n\n")))) (def elves-totals (map #(reduce + %) elves-rations)) (def sorted-totals (sort elves-totals)) diff --git a/2022/day1.nim b/2022/day1.nim index e09eb49..b708408 100644 --- a/2022/day1.nim +++ b/2022/day1.nim @@ -3,7 +3,7 @@ import strutils import sugar from algorithm import sorted -let inputString = strip readFile "day1-input" +let inputString = strip readFile "input/1" let elfStrings = split(inputString, "\n\n") let elfRations = collect newSeq: for elf in elfStrings: collect newSeq: diff --git a/2022/day1.scala b/2022/day1.scala index 0e0585b..677101d 100644 --- a/2022/day1.scala +++ b/2022/day1.scala @@ -1,7 +1,7 @@ import scala.collection.mutable.ArrayBuffer import scala.io.Source -val filename = "day1-input" +val filename = "input/1" class Elf: @@ -23,9 +23,6 @@ class Elf: elves.last.foodCalories = line.toInt :: elves.last.foodCalories elves.last.calculateTotalCalories() - // for (elf <- elves) - // println(s"${elf.totalCalories}: ${elf.foodCalories}") - // Part 1 solution: Total calories held by elf with the most total calories println(s"${elves.map(elf => elf.totalCalories).max}") // Part 2 solution: Total calories held by the top 3 elves diff --git a/2022/day2-v2.scala b/2022/day2-v2.scala index 1f74413..3c829a2 100644 --- a/2022/day2-v2.scala +++ b/2022/day2-v2.scala @@ -20,7 +20,7 @@ enum RPS(val score: Int): val moveMap = Map("A"->RPS.Rock, "B"->RPS.Paper, "C"->RPS.Scissors, "X"->RPS.Rock, "Y"->RPS.Paper, "Z"->RPS.Scissors) @main def main() = - val strategyGuide = Source.fromFile("day2-input").getLines.map(_.split(" ")).toArray // Can't leave it lazy as Part 1 will consume it + val strategyGuide = Source.fromFile("input/2").getLines.map(_.split(" ")).toArray // Can't leave it lazy as Part 1 will consume it // val strategyGuide = Source.fromString("A Y\nB X\nC Z\n").getLines.map(_.split(" ")).toArray // Part 1 - evaluate all moves in the guide using moveMap and tally score diff --git a/2022/day2.clj b/2022/day2.clj index 92d90f2..059bbae 100644 --- a/2022/day2.clj +++ b/2022/day2.clj @@ -1,5 +1,5 @@ (require '[clojure.string :as str]) -(def filename "day2-input") +(def filename "input/2") (def move-pairs (map #(str/split % #" ") (str/split-lines (slurp filename)))) (def move-map {"A" 1 "B" 2 "C" 3 "X" 1 "Y" 2 "Z" 3}) (defn draw-win-lose-score [our-move their-move] diff --git a/2022/day2.nim b/2022/day2.nim index 72ae652..29877d5 100644 --- a/2022/day2.nim +++ b/2022/day2.nim @@ -7,7 +7,7 @@ import tables proc `%%` (a: int, b: int): int = floor_mod a, b let move_map = to_table {'A': 1, 'B': 2, 'C': 3, 'X': 1, 'Y': 2, 'Z': 3} -let rounds = split_lines strip read_file "day2-input" +let rounds = split_lines strip read_file "input/2" proc round_score(us: int, them: int): int = us + [3, 6, 0][(us-them) %% 3] diff --git a/2022/day2.scala b/2022/day2.scala index fb72a4d..94158d8 100644 --- a/2022/day2.scala +++ b/2022/day2.scala @@ -27,7 +27,7 @@ def resultScore(a: RPS, b: RPS) = a <=> b match val moveMap = Map("A"->RPS.Rock, "B"->RPS.Paper, "C"->RPS.Scissors, "X"->RPS.Rock, "Y"->RPS.Paper, "Z"->RPS.Scissors) @main def main() = - val strategyGuide = Source.fromFile("day2-input").getLines.map(_.split(" ")).toArray // Can't leave it lazy as Part 1 will consume it + val strategyGuide = Source.fromFile("input/2").getLines.map(_.split(" ")).toArray // Can't leave it lazy as Part 1 will consume it // val strategyGuide = Source.fromString("A Y\nB X\nC Z\n").getLines.map(_.split(" ")).toArray // Part 1 - evaluate all moves in the guide using moveMap and tally score diff --git a/2022/day3.py b/2022/day3.py index da6bc3f..f534669 100644 --- a/2022/day3.py +++ b/2022/day3.py @@ -1,4 +1,4 @@ -with open('day3-input', 'r') as file: +with open('input/3', 'r') as file: input = file.read().strip().split('\n') def prio(character): diff --git a/2022/day3.scala b/2022/day3.scala index 08cd55e..ecf37c3 100644 --- a/2022/day3.scala +++ b/2022/day3.scala @@ -9,7 +9,7 @@ def priorityScore(c: Char): Int = c match @main def main() = - val inputLines = Source.fromFile("day3-input").getLines.toArray // Can't leave it lazy as Part 1 will consume it + val inputLines = Source.fromFile("input/3").getLines.toArray // Can't leave it lazy as Part 1 will consume it // Part 1 - find items common between first half and second half of each line println(inputLines.map(line => diff --git a/2022/day1-input b/2022/input/1 similarity index 100% rename from 2022/day1-input rename to 2022/input/1 diff --git a/2022/day2-input b/2022/input/2 similarity index 100% rename from 2022/day2-input rename to 2022/input/2 diff --git a/2022/day3-input b/2022/input/3 similarity index 100% rename from 2022/day3-input rename to 2022/input/3