Skip to content

Commit afed02d

Browse files
committed
testdekning d1 og d2
1 parent 1bd5fac commit afed02d

File tree

8 files changed

+62
-21
lines changed

8 files changed

+62
-21
lines changed

input/2024/input3.nippy

13.5 KB
Binary file not shown.

input/2024/input4.nippy

11.2 KB
Binary file not shown.

notebooks/y2024/d01.clj

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
^{:nextjournal.clerk/visibility {:code :hide :result :hide}}
1+
^{:nextjournal.clerk/visibility {:code :hide :result :hide}
2+
:kindly/hide-code true}
23
(ns y2024.d01
34
(:require
45
[nextjournal.clerk :as clerk]
@@ -29,7 +30,8 @@
2930

3031
^{:nextjournal.clerk/visibility {:result :hide}}
3132
(require '[debux.core :as d])
32-
^{:nextjournal.clerk/visibility {:result :hide}}
33+
^{:nextjournal.clerk/visibility {:result :hide}
34+
:kind/hidden true}
3335
(d/set-debug-mode! false)
3436

3537
; Så kan vi starte med å få tak i listene:
@@ -44,6 +46,17 @@
4446
(apply mapv vector))
4547
:level 2))
4648

49+
(defmacro dbg-output [& body]
50+
`(let [set-debug-mode!# (requiring-resolve 'debux.core/set-debug-mode!)]
51+
(set-debug-mode!# true)
52+
(let [debug-output#
53+
(with-out-str ~@body)]
54+
(set-debug-mode!# false)
55+
56+
^:kind/hiccup [:pre debug-output#])))
57+
58+
(dbg-output (get-lists test-data))
59+
4760
; dbg-makroen lar oss inspisere hva som skjer i hvert steg
4861
; av get-lists-funksjonen:
4962
^{:nextjournal.clerk/visibility {:result :hide}}
@@ -57,7 +70,6 @@
5770
(d/set-debug-mode! false)
5871
debug-output)))
5972

60-
6173
; Når vi har listene kan vi sortere og finne differansen
6274
; mellom hvert siffer, og summere:
6375

@@ -91,7 +103,7 @@
91103
(d/set-debug-mode! false)
92104
debug-output))))
93105

94-
(= 2756096 (total-difference (input/get-input 2024 1)))
106+
(total-difference (input/get-input 2024 1))
95107

96108
; ## Del 2
97109

@@ -119,4 +131,4 @@
119131
(d/set-debug-mode! false)
120132
debug-output))))
121133

122-
(= 23117829 (total-similarity-score (input/get-input 2024 1)))
134+
(total-similarity-score (input/get-input 2024 1))

notebooks/y2024/d02.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
(safe-lines test-data)
4343

44-
(= 314 (safe-lines (to-matrix (input/get-input 2024 2))))
44+
(safe-lines (to-matrix (input/get-input 2024 2)))
4545

4646
; ## Del 2
4747

@@ -79,4 +79,4 @@
7979
; Brute-force-løsningen kjører heldigvis på beskjedne 11ms på
8080
; inputten i dag, så vi slipper å optimalisere denne gangen
8181

82-
(= 373 (safeish-lines (to-matrix (input/get-input 2024 2))))
82+
(safeish-lines (to-matrix (input/get-input 2024 2)))

notebooks/y2024/d03.clj

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
^{:nextjournal.clerk/visibility {:code :hide}}
2-
(ns y2024.d03)
2+
(ns y2024.d03
3+
(:require
4+
[advent-of-code-clj.input :as input]))
35

46
; # 2024, dag 3
57

@@ -92,9 +94,7 @@
9294

9395
; Fortsatt riktig på testdata, og nå blir det også riktig på inputten:
9496

95-
^{:nextjournal.clerk/visibility {:result :hide}}
96-
(comment
97-
(= 90669332 (process-operations (get-operations (slurp "input/2024/input3.txt")))))
97+
(= 90669332 (process-operations (get-operations (input/get-input 2024 3))))
9898

9999
; ## Del 2 igjen
100100

@@ -123,6 +123,4 @@
123123

124124
(prep-input "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?don't()mul(8,5))")
125125

126-
^{:nextjournal.clerk/visibility {:result :hide}}
127-
(comment
128-
(= 90669332 (parse-and-multiply (prep-input (slurp "input/2024/input3.txt")))))
126+
(= 90669332 (parse-and-multiply (prep-input (input/get-input 2024 3))))

notebooks/y2024/d04.clj

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
(ns y2024.d04
22
(:require [advent-of-code-clj.utils :as utils]
3-
[clojure.core.matrix :as mx]))
3+
[clojure.core.matrix :as mx]
4+
[advent-of-code-clj.input :as input]))
5+
6+
; # 2024, dag 4
7+
8+
; ## Del 1
9+
10+
; Vi skal finne ordet "XMAS" i en matrise, i alle retninger
11+
; (horisontalt, verticalt, diagonalt).
412

513
(def test-data (utils/coord-map (utils/text->matrix "MMMSXXMASM
614
MSAMXMSMSA
@@ -57,8 +65,7 @@ MXMXAXMASX")))
5765

5866
(= 18 (part-1 test-data))
5967

60-
(comment
61-
(= 2547 (part-1 (utils/coord-map (utils/text->matrix (slurp "input/2024/input4.txt"))))))
68+
(delay (= 2547 (part-1 (utils/coord-map (utils/text->matrix (input/get-input 2024 4))))))
6269

6370
(defn find-x-mas [coord-map [x y]]
6471
(let [diagonals [[[(dec x) (dec y)] [x y] [(inc x) (inc y)]]
@@ -77,8 +84,7 @@ MXMXAXMASX")))
7784

7885
(= 9 (part-2 test-data))
7986

80-
(comment
81-
(= 1939 (part-2 (utils/coord-map (utils/text->matrix (slurp "input/2024/input4.txt"))))))
87+
(delay (= 1939 (part-2 (utils/coord-map (utils/text->matrix (input/get-input 2024 4))))))
8288

8389
; # Igjen, med matriser
8490

@@ -135,5 +141,4 @@ MXMXAXMASX")
135141

136142
(= 18 (part-1-matrix test-input))
137143

138-
(comment
139-
(= 2547 (part-1-matrix (slurp "input/2024/input4.txt"))))
144+
(delay (= 2547 (part-1-matrix (input/get-input 2024 4))))

test/y2024/d01_test.clj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns y2024.d01-test
2+
(:require
3+
[clojure.test :refer [deftest is]]
4+
[y2024.d01 :as sut]
5+
[advent-of-code-clj.input :as input]))
6+
7+
(deftest part-1-test
8+
(is (= 11 (sut/total-difference sut/test-data)))
9+
(is (= 2756096 (sut/total-difference (input/get-input 2024 1)))))
10+
11+
(deftest part-2-test
12+
(is (= 31 (sut/total-similarity-score sut/test-data)))
13+
(is (= 23117829 (sut/total-similarity-score (input/get-input 2024 1)))))

test/y2024/d02_test.clj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns y2024.d02-test
2+
(:require
3+
[advent-of-code-clj.input :as input]
4+
[clojure.test :refer [deftest is]]
5+
[y2024.d02 :as sut]))
6+
7+
(deftest part-1-test
8+
(is (= 2 (sut/safe-lines sut/test-data)))
9+
(is (= 314 (sut/safe-lines (sut/to-matrix (input/get-input 2024 2))))))
10+
11+
(deftest part-2-test
12+
(is (= 4 (sut/safeish-lines sut/test-data)))
13+
(is (= 373 (sut/safeish-lines (sut/to-matrix (input/get-input 2024 2))))))

0 commit comments

Comments
 (0)