Solve AOC Day 10 pt 1
This commit is contained in:
9
projects/aoc/src/year2020/Adapters.hx
Normal file
9
projects/aoc/src/year2020/Adapters.hx
Normal file
@@ -0,0 +1,9 @@
|
||||
package year2020;
|
||||
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@:build(kiss.Kiss.build("src/year2020/Adapters.kiss"))
|
||||
class Adapters {}
|
12
projects/aoc/src/year2020/Adapters.kiss
Normal file
12
projects/aoc/src/year2020/Adapters.kiss
Normal file
@@ -0,0 +1,12 @@
|
||||
(defun differences [:kiss.List<Int> ratings]
|
||||
(for idx (range (- ratings.length 1))
|
||||
(- (nth ratings (+ idx 1)) (nth ratings idx))))
|
||||
|
||||
(defun distribution [:kiss.List<Int> numbers]
|
||||
(let [:Map<Int,Int> dist (new Map)]
|
||||
(doFor num numbers
|
||||
(dictSet dist num
|
||||
(if (dist.exists num)
|
||||
(+ 1 (dictGet dist num))
|
||||
1)))
|
||||
dist))
|
@@ -13,6 +13,7 @@ import year2020.Seating;
|
||||
import year2020.Customs;
|
||||
import year2020.Bags;
|
||||
import year2020.BootCode;
|
||||
import year2020.Adapters;
|
||||
|
||||
@:build(kiss.Kiss.build("src/year2020/Solutions.kiss"))
|
||||
class Solutions {}
|
||||
|
@@ -98,5 +98,14 @@
|
||||
[35 20 15 25 47 40 62 55 65 95 102 117 150 182 127 219 299 277 309 576]))))
|
||||
(let [tuple (SummingTuples.contiguousSumTuple 133015568 (Util.readInts "src/year2020/inputs/day9.txt"))]
|
||||
(assert (= 16107959 (+ (apply min tuple) (apply max tuple)))))
|
||||
|
||||
// Day 10
|
||||
(let [adapters (Util.readInts "src/year2020/inputs/day10.txt")]
|
||||
(.sort adapters Reflect.compare)
|
||||
(adapters.unshift 0)
|
||||
(adapters.push (+ 3 (last adapters)))
|
||||
(let [diffs (Adapters.differences adapters)
|
||||
dist (Adapters.distribution diffs)]
|
||||
(assert (= 1998 (* (dictGet dist 1) (dictGet dist 3))))))
|
||||
)
|
||||
|
||||
|
@@ -17,7 +17,8 @@
|
||||
(lambda [line] (< 0 line.length))))
|
||||
(lambda [lines] (< 0 lines.length))))
|
||||
|
||||
(defun readInts [file] (let [lines (readLines file)] (lines.map Std.parseInt)))
|
||||
// TODO won't need to specify type here if last is not a quickNth
|
||||
(defun :kiss.List<Int> readInts [file] (let [lines (readLines file)] (lines.map Std.parseInt)))
|
||||
|
||||
(defun countChar [char str]
|
||||
(count (str.split "") (lambda [c] ?(= c char))))
|
100
projects/aoc/src/year2020/inputs/day10.txt
Normal file
100
projects/aoc/src/year2020/inputs/day10.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
46
|
||||
63
|
||||
21
|
||||
115
|
||||
125
|
||||
35
|
||||
89
|
||||
17
|
||||
116
|
||||
90
|
||||
51
|
||||
66
|
||||
111
|
||||
142
|
||||
148
|
||||
60
|
||||
2
|
||||
50
|
||||
82
|
||||
20
|
||||
47
|
||||
24
|
||||
80
|
||||
101
|
||||
103
|
||||
16
|
||||
34
|
||||
72
|
||||
145
|
||||
141
|
||||
124
|
||||
14
|
||||
123
|
||||
27
|
||||
62
|
||||
61
|
||||
95
|
||||
138
|
||||
29
|
||||
7
|
||||
149
|
||||
147
|
||||
104
|
||||
152
|
||||
22
|
||||
81
|
||||
11
|
||||
96
|
||||
97
|
||||
30
|
||||
41
|
||||
98
|
||||
59
|
||||
45
|
||||
88
|
||||
37
|
||||
10
|
||||
114
|
||||
110
|
||||
4
|
||||
56
|
||||
122
|
||||
139
|
||||
117
|
||||
108
|
||||
91
|
||||
36
|
||||
146
|
||||
131
|
||||
109
|
||||
31
|
||||
75
|
||||
70
|
||||
140
|
||||
38
|
||||
121
|
||||
3
|
||||
28
|
||||
118
|
||||
54
|
||||
107
|
||||
84
|
||||
15
|
||||
76
|
||||
71
|
||||
102
|
||||
130
|
||||
132
|
||||
87
|
||||
55
|
||||
129
|
||||
83
|
||||
23
|
||||
42
|
||||
69
|
||||
1
|
||||
77
|
||||
135
|
||||
128
|
||||
94
|
Reference in New Issue
Block a user