Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1139396

Browse files
committed
part 1 day 10
1 parent 64e27b6 commit 1139396

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

day10/input.txt

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2
2+
49
3+
78
4+
116
5+
143
6+
42
7+
142
8+
87
9+
132
10+
86
11+
67
12+
44
13+
136
14+
82
15+
125
16+
1
17+
108
18+
123
19+
46
20+
37
21+
137
22+
148
23+
106
24+
121
25+
10
26+
64
27+
165
28+
17
29+
102
30+
156
31+
22
32+
117
33+
31
34+
38
35+
24
36+
69
37+
131
38+
144
39+
162
40+
63
41+
171
42+
153
43+
90
44+
9
45+
107
46+
79
47+
7
48+
55
49+
138
50+
34
51+
52
52+
77
53+
152
54+
3
55+
158
56+
100
57+
45
58+
129
59+
130
60+
135
61+
23
62+
93
63+
96
64+
103
65+
124
66+
95
67+
8
68+
62
69+
39
70+
118
71+
164
72+
172
73+
75
74+
122
75+
20
76+
145
77+
14
78+
112
79+
61
80+
43
81+
141
82+
30
83+
85
84+
101
85+
151
86+
29
87+
113
88+
94
89+
68
90+
58
91+
76
92+
97
93+
28
94+
111
95+
128
96+
21
97+
11
98+
163
99+
161
100+
4
101+
168
102+
157
103+
27
104+
72

day10/program.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fs = require('fs');
2+
3+
const data = fs.readFileSync('./input.txt', 'utf-8');
4+
let adapters = data.split("\n");
5+
6+
adapters.forEach((a, i) => {
7+
adapters[i] = parseInt(a);
8+
});
9+
10+
findAdapterJumps(adapters);
11+
12+
13+
function findAdapterJumps(items) {
14+
items.sort((a,b) => { return a > b ? 1 : -1});
15+
16+
let jump1 = 0;
17+
let jump3 = 1;
18+
let currentCharge = 0;
19+
20+
items.forEach(i => {
21+
if (i - currentCharge === 1) jump1++;
22+
if (i - currentCharge === 3) jump3++;
23+
currentCharge = i;
24+
});
25+
26+
console.log(jump1, jump3, 'answer part 1: ', jump1 * jump3);
27+
}

0 commit comments

Comments
 (0)