diff --git a/2022/02/example b/2022/02/example new file mode 100644 index 0000000..db60e36 --- /dev/null +++ b/2022/02/example @@ -0,0 +1,3 @@ +A Y +B X +C Z diff --git a/2022/02/src/day02.clj b/2022/02/src/day02.clj new file mode 100644 index 0000000..73fee63 --- /dev/null +++ b/2022/02/src/day02.clj @@ -0,0 +1,58 @@ +(ns day02 + (:require + [clojure.string :as str])) + +;; A, X - 1 Rock +;; B, Y - 2 Paper +;; C, Z - 3 Scissors +;; +;; Lose - 0 +;; Draw - 3 +;; Win - 6 +(def score-table + {"B X" 1 + "C Y" 2 + "A Z" 3 + "A X" 4 + "B Y" 5 + "C Z" 6 + "C X" 7 + "A Y" 8 + "B Z" 9}) + +(defn part1 [games] + (->> games + (map score-table) + (apply +))) + +;; X lose +;; Y draw +;; Z win +(def part2-map + {"A X" "A Z" + "A Y" "A X" + "A Z" "A Y" + "B X" "B X" + "B Y" "B Y" + "B Z" "B Z" + "C X" "C Y" + "C Y" "C Z" + "C Z" "C X"}) + +(defn part2 [games] + (->> games + (map part2-map) + part1)) + +(comment + (def input (str/split-lines (slurp "example"))) + + (= 15 (part1 input)) + (= 12 (part2 input)) + ) + +(defn main [& _args] + (let [input (str/split-lines (slurp "input"))] + (do + (println (str "Part 1: " (part1 input))) + (println (str "Part 2: " (part2 input))))))