Skip to content

Commit 20cdc2e

Browse files
committed
Cleanup gamle notebooks
1 parent 0a59b64 commit 20cdc2e

File tree

5 files changed

+39
-39
lines changed

5 files changed

+39
-39
lines changed

notebooks/y2022/d01.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
[nextjournal.clerk :as clerk]
99
[advent-of-code-clj.input :as input]))
1010

11-
^{::clerk/visibility {:code :hide}}
12-
(clerk/md "# Advent of code 2022, part 01")
11+
12+
; # Advent of code 2022, part 01
1313

1414
; Create a parser to convert the following test-data into lists:
1515

16-
^{::clerk/visibility {:code :hide}} (def test-data "1000
16+
^{:nextjournal.clerk/visibility {:code :hide}} (def test-data "1000
1717
2000
1818
3000
1919
@@ -28,28 +28,28 @@
2828
2929
10000")
3030

31-
{::clerk/visibility {:code :show :result :hide}}
31+
{:nextjournal.clerk/visibility {:code :show :result :hide}}
3232

3333
(defn- parse [text]
3434
(->> text split-newline (map str/split-lines) (emap parse-long)))
3535

36-
^{::clerk/visibility {:code :hide :result :show}}
36+
^{:nextjournal.clerk/visibility {:code :hide :result :show}}
3737
(clerk/example
3838
(parse test-data))
3939

40-
{::clerk/visibility {:code :show :result :show}}
40+
{:nextjournal.clerk/visibility {:code :show :result :show}}
4141

4242
;; ## Part 1
4343
;; > find the maximum calories carried by one elf
4444

4545
;; Could use "(apply max ...)" instead of sorting, but part 2
4646
;; needs the maximum 3 calorie counts, so a sorted list is more useful
4747

48-
^{::clerk/visibility {:result :hide}}
48+
^{:nextjournal.clerk/visibility {:result :hide}}
4949
(defn sorted-calories [data]
5050
(->> data (map sum) sort-))
5151

52-
^{::clerk/visibility {:result :hide}}
52+
^{:nextjournal.clerk/visibility {:result :hide}}
5353
(defn part-1 [data]
5454
(->> data parse sorted-calories first))
5555
(part-1 test-data)
@@ -61,7 +61,7 @@
6161
;; ## Part 2
6262
;; > find the amount of calories carried by the "top 3" elves
6363

64-
^{::clerk/visibility {:result :hide}}
64+
^{:nextjournal.clerk/visibility {:result :hide}}
6565
(defn part-2 [data]
6666
(->> data parse sorted-calories (take 3) sum))
6767

notebooks/y2022/d02.clj

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
:rock :scissors})
2222
(def wins-to (set/map-invert loses-to))
2323

24-
^{::clerk/visibility {:result :hide}}
24+
^{:nextjournal.clerk/visibility {:result :hide}}
2525
(defn decide-outcome [{:keys [player opponent]}]
2626
(cond
2727
(= player opponent) :draw
2828
(= opponent (wins-to player)) :opponent-wins
2929
(= opponent (loses-to player)) :player-wins))
3030

31-
^{::clerk/visibility {:result :hide}}
31+
^{:nextjournal.clerk/visibility {:result :hide}}
3232
(defn calculate-score [{:keys [player] :as game}]
3333
(+ (outcome-points (decide-outcome game))
3434
(hand-points player)))
3535

36-
^{::clerk/visibility {:result :hide}}
36+
^{:nextjournal.clerk/visibility {:result :hide}}
3737
(defn part-1 [data]
3838
(letfn [(calculate [line]
3939
(calculate-score
@@ -45,14 +45,14 @@
4545
(def desired-outcome {\X :lose
4646
\Y :draw
4747
\Z :win})
48-
^{::clerk/visibility {:result :hide}}
48+
^{:nextjournal.clerk/visibility {:result :hide}}
4949
(defn decide-hand [opponent desired-outcome]
5050
(case desired-outcome
5151
:draw opponent
5252
:win (wins-to opponent)
5353
:lose (loses-to opponent)))
5454

55-
^{::clerk/visibility {:result :hide}}
55+
^{:nextjournal.clerk/visibility {:result :hide}}
5656
(defn part-2 [data]
5757
(letfn [(calculate [line]
5858
(let [opponent-hand (opponent-strategy (first line))]
@@ -62,7 +62,7 @@
6262
(transduce (map (comp calculate)) +
6363
(str/split-lines data))))
6464

65-
^{::clerk/visibility {:code :hide}}
65+
^{:nextjournal.clerk/visibility {:code :hide}}
6666
(clerk/code '(= 11767 (part-1 (slurp "input/2022/02.txt"))))
67-
^{::clerk/visibility {:code :hide}}
68-
(clerk/code '(= 13886 (part-2 (slurp "input/2022/02.txt"))))
67+
^{:nextjournal.clerk/visibility {:code :hide}}
68+
(clerk/code '(= 13886 (part-2 (slurp "input/2022/02.txt"))))

notebooks/y2022/d16.clj

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
;; > For example, suppose you had the following scan output:
1818

19-
^{::clerk/visibility {:result :hide}}
19+
^{:nextjournal.clerk/visibility {:result :hide}}
2020
(def test-data "Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
2121
Valve BB has flow rate=13; tunnels lead to valves CC, AA
2222
Valve CC has flow rate=2; tunnels lead to valves DD, BB
@@ -36,10 +36,10 @@ Valve JJ has flow rate=21; tunnel leads to valve II")
3636

3737
;; Start by parsing the test-data into a map where each valve is a key, and the value is a map listing the pressure and neighbouring nodes:
3838

39-
^{::clerk/visibility {:result :hide}}
39+
^{:nextjournal.clerk/visibility {:result :hide}}
4040
(require '[clojure.string :as str])
4141

42-
^{::clerk/visibility {:result :hide}}
42+
^{:nextjournal.clerk/visibility {:result :hide}}
4343
(defn parse [data]
4444
(->> data
4545
str/split-lines
@@ -55,15 +55,15 @@ Valve JJ has flow rate=21; tunnel leads to valve II")
5555
:pressure pressure}])))
5656
(into {})))
5757

58-
^{::clerk/visibility {:code :hide}}
58+
^{:nextjournal.clerk/visibility {:code :hide}}
5959
(clerk/example
6060
(parse test-data))
6161

6262
;; To find the shortest path we'll use the excellent Ubergraph library:
6363

64-
^{::clerk/visibility {:result :hide}}
64+
^{:nextjournal.clerk/visibility {:result :hide}}
6565
(require '[ubergraph.alg :as ua])
66-
^{::clerk/visibility {:result :hide}}
66+
^{:nextjournal.clerk/visibility {:result :hide}}
6767
(defn shortest-path [start-pos end-pos data]
6868
(ua/shortest-path (fn [coord]
6969
(map (fn [neighbour] {:dest neighbour}) (-> data coord :next)))
@@ -73,7 +73,7 @@ Valve JJ has flow rate=21; tunnel leads to valve II")
7373
;; Once refactored and shrunk down, this function ended up being almost
7474
;; a copy-paste of [@volesen's solution](https://github.com/volesen/aoc2022/blob/main/day16/day16.clj#L48C10-L48C10)
7575

76-
^{::clerk/visibility {:result :hide}}
76+
^{:nextjournal.clerk/visibility {:result :hide}}
7777
(defn max-pressure [time-remaining start non-zero-valves elephant? data]
7878
(let [next-nodes* (keep (fn [node]
7979
(let [time-to-open (inc (:cost (shortest-path start node data)))]
@@ -89,31 +89,31 @@ Valve JJ has flow rate=21; tunnel leads to valve II")
8989
elephant? (conj (max-pressure 26 :AA non-zero-valves false data)))]
9090
(+ (* time-remaining (-> data start :pressure)) (apply max 0 next-nodes))))
9191

92-
^{::clerk/visibility {:result :hide}}
92+
^{:nextjournal.clerk/visibility {:result :hide}}
9393
(defn part-1 [data]
9494
(with-redefs [shortest-path (memoize shortest-path)]
9595
(let [data (parse data)
9696
non-zero-valves (set (remove (fn [valve] (zero? (:pressure (valve data)))) (keys data)))]
9797
(max-pressure 30 :AA non-zero-valves false data))))
9898

99-
^{::clerk/visibility {:code :hide}}
99+
^{:nextjournal.clerk/visibility {:code :hide}}
100100
(clerk/example (= 1651 (part-1 test-data)))
101101

102102
;; Applying it to our input we get:
103-
^{::clerk/visibility {:code :hide}}
103+
^{:nextjournal.clerk/visibility {:code :hide}}
104104
(clerk/code
105105
'(= 1896 (part-1 (slurp "input/2022/16.txt"))))
106106

107-
^{::clerk/visibility {:result :hide}}
107+
^{:nextjournal.clerk/visibility {:result :hide}}
108108
(defn part-2 [data-string]
109109
(with-redefs [shortest-path (memoize shortest-path)]
110110
(let [data (parse data-string)
111111
non-zero-valves (set (remove (fn [valve] (zero? (:pressure (valve data)))) (keys data)))]
112112
(max-pressure 26 :AA non-zero-valves true data))))
113-
^{::clerk/visibility {:code :hide}}
113+
^{:nextjournal.clerk/visibility {:code :hide}}
114114
(clerk/example (= 1707 (part-2 test-data)))
115115

116116
;; Applying it to our input we get:
117-
^{::clerk/visibility {:code :hide}}
117+
^{:nextjournal.clerk/visibility {:code :hide}}
118118
(clerk/code
119119
'(= 2576 (part-2 (slurp "input/2022/16.txt"))))

notebooks/y2022/d18.clj

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; # Year 2022 - Day 18
66

7-
^{::clerk/visibility {:result :hide}}
7+
^{:nextjournal.clerk/visibility {:result :hide}}
88
(def test-data "2,2,2
99
1,2,2
1010
3,2,2
@@ -19,7 +19,7 @@
1919
2,1,5
2020
2,3,5")
2121

22-
{::clerk/visibility {:result :hide}}
22+
{:nextjournal.clerk/visibility {:result :hide}}
2323

2424
(require '[advent-of-code-clj.utils :as u]
2525
'[clojure.core.matrix :as mx]
@@ -43,9 +43,9 @@
4343
;; For every immediate neighbour we lose two sides
4444
(* (count (neighbours points)) 2))))
4545

46-
{::clerk/visibility {:result :show}}
46+
{:nextjournal.clerk/visibility {:result :show}}
4747

48-
^{::clerk/visibility {:code :hide}}
48+
^{:nextjournal.clerk/visibility {:code :hide}}
4949
(clerk/example
5050
(= 64 (part-1 test-data)))
5151

@@ -54,7 +54,7 @@
5454
(clerk/code
5555
'(= 4302 (part-1 (slurp "input/2022/18.txt"))))
5656

57-
{::clerk/visibility {:result :hide}}
57+
{:nextjournal.clerk/visibility {:result :hide}}
5858

5959
(defn adjacents [[x y z]]
6060
(set (u/adjacent-hv x y z)))
@@ -106,9 +106,9 @@
106106
;; For every immediate neighbour we lose two sides
107107
(* (count (neighbours diff)) 2))))
108108

109-
{::clerk/visibility {:result :show}}
109+
{:nextjournal.clerk/visibility {:result :show}}
110110

111-
{::clerk/visibility {:code :hide}}
111+
{:nextjournal.clerk/visibility {:code :hide}}
112112
(clerk/example
113113
(= 58 (part-2 test-data)))
114114

notebooks/y2022/d22.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
;; We use the parsed map to find the starting position:
7676

7777
^{:nextjournal.clerk/visibility {:result :hide}}
78-
(defn find-starting-position [{:keys [open-spaces] :as map-coords}]
78+
(defn find-starting-position [{:keys [open-spaces] :as _map-coords}]
7979
{:coord (->> open-spaces
8080
(filter (fn [[x y]] (zero? y)))
8181
(sort-by first)
@@ -347,4 +347,4 @@
347347
starting-position (find-starting-position map-coords)]
348348
(->> (reduce (partial make-move (partial update-position-cube manual-quadrant-mapping-input) map-coords) starting-position movements)
349349
calculate
350-
(= 195032))))
350+
(= 195032))))

0 commit comments

Comments
 (0)