File tree Expand file tree Collapse file tree 3 files changed +177
-0
lines changed Expand file tree Collapse file tree 3 files changed +177
-0
lines changed Original file line number Diff line number Diff line change 1+ 8
2+ 131
3+ 91
4+ 35
5+ 47
6+ 116
7+ 105
8+ 121
9+ 56
10+ 62
11+ 94
12+ 72
13+ 13
14+ 82
15+ 156
16+ 102
17+ 12
18+ 59
19+ 31
20+ 138
21+ 46
22+ 120
23+ 7
24+ 127
25+ 126
26+ 111
27+ 2
28+ 123
29+ 22
30+ 69
31+ 18
32+ 157
33+ 75
34+ 149
35+ 88
36+ 81
37+ 23
38+ 98
39+ 132
40+ 1
41+ 63
42+ 142
43+ 37
44+ 133
45+ 61
46+ 112
47+ 122
48+ 128
49+ 155
50+ 145
51+ 139
52+ 66
53+ 42
54+ 134
55+ 24
56+ 60
57+ 9
58+ 28
59+ 17
60+ 29
61+ 101
62+ 148
63+ 96
64+ 68
65+ 25
66+ 19
67+ 6
68+ 67
69+ 113
70+ 55
71+ 40
72+ 135
73+ 97
74+ 79
75+ 48
76+ 159
77+ 14
78+ 43
79+ 86
80+ 36
81+ 41
82+ 85
83+ 87
84+ 119
85+ 30
86+ 108
87+ 80
88+ 152
89+ 158
90+ 151
91+ 32
92+ 78
93+ 150
94+ 95
95+ 3
96+ 52
97+ 49
Original file line number Diff line number Diff line change 1+ export const part1 = ( input : string ) => {
2+ const joltage = [ 0 , ...input . split ( '\n' ) ] . map ( Number ) . sort ( ( a , b ) => a - b ) ;
3+
4+ let oneDiff = 0 ;
5+ let threeDiff = 1 ; // 3 higher than the highest-rated adapter.
6+
7+ joltage . forEach ( ( current , i ) => {
8+ const diff = joltage [ i + 1 ] - current ;
9+ if ( diff === 1 ) oneDiff ++ ;
10+ else if ( diff === 3 ) threeDiff ++ ;
11+ } ) ;
12+
13+ return oneDiff * threeDiff ;
14+ } ;
Original file line number Diff line number Diff line change 1+ import { readInput } from '../../utils' ;
2+
3+ import { part1 } from './part1' ;
4+
5+ describe ( 'Advent of Code 2020 - Day 10' , ( ) => {
6+ let input : string ;
7+ const testInput = `28
8+ 33
9+ 18
10+ 42
11+ 31
12+ 14
13+ 46
14+ 20
15+ 48
16+ 47
17+ 24
18+ 23
19+ 49
20+ 45
21+ 19
22+ 38
23+ 39
24+ 11
25+ 1
26+ 32
27+ 25
28+ 35
29+ 8
30+ 17
31+ 7
32+ 9
33+ 4
34+ 2
35+ 34
36+ 10
37+ 3` ;
38+
39+ beforeAll ( async ( ) => {
40+ input = await readInput ( __dirname + '/input' ) ;
41+ } ) ;
42+
43+ describe ( 'part 1' , ( ) => {
44+ it ( 'should output 7*5' , ( ) => {
45+ const input = `16
46+ 10
47+ 15
48+ 5
49+ 1
50+ 11
51+ 7
52+ 19
53+ 6
54+ 12
55+ 4` ;
56+ expect ( part1 ( input ) ) . toBe ( 7 * 5 ) ;
57+ } ) ;
58+ it ( 'should output 22*10 ' , ( ) => {
59+ expect ( part1 ( testInput ) ) . toBe ( 22 * 10 ) ;
60+ } ) ;
61+
62+ it ( 'should output 2112 from input' , ( ) => {
63+ expect ( part1 ( input ) ) . toBe ( 2112 ) ;
64+ } ) ;
65+ } ) ;
66+ } ) ;
You can’t perform that action at this time.
0 commit comments