Skip to content

Commit 34e1dce

Browse files
committed
Fix lint issues
1 parent 3702bb9 commit 34e1dce

File tree

11 files changed

+169
-117
lines changed

11 files changed

+169
-117
lines changed

2018/10/solve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const solve2 = () => {
1414
};
1515

1616
solve1();
17-
//solve2();
17+
solve2();

2018/10/stars.js

Lines changed: 90 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
const fs = require('fs');
23
let path = require('path');
34

@@ -35,7 +36,6 @@ const createGrid = (gridWidth, gridHeight) => {
3536
return grid;
3637
};
3738

38-
3939
const printGrid = (grid) => {
4040
let string = '';
4141
grid.forEach((innerGrid) => {
@@ -59,27 +59,36 @@ const plotStarsOnGrid = (stars) => {
5959
}
6060
};
6161

62-
const calculateNextStarState = stars => stars.reduce((res, [x, y, dx, dy]) => {
63-
x += dx;
64-
y += dy;
65-
res.push([x, y, dx, dy]);
66-
res.push([x, y, dx, dy]);
67-
return res;
68-
}, []);
69-
62+
const calculateNextStarState = (stars) =>
63+
stars.reduce((res, [x, y, dx, dy]) => {
64+
x += dx;
65+
y += dy;
66+
res.push([x, y, dx, dy]);
67+
res.push([x, y, dx, dy]);
68+
return res;
69+
}, []);
7070

7171
const findMessage = (rows) => {
7272
let stars = rows.map((row) => {
7373
/* eslint-disable-next-line max-len */
74-
const [, x, y, dX, dY] = row.match(/position=<\s?(-?\d+), \s?(-?\d+)> velocity=<\s?(-?\d+), \s?(-?\d+)>/).map(v => +v);
74+
const [, x, y, dX, dY] = row
75+
.match(
76+
/position=<\s?(-?\d+), \s?(-?\d+)> velocity=<\s?(-?\d+), \s?(-?\d+)>/,
77+
)
78+
.map((v) => +v);
7579
return [x, y, dX, dY];
7680
});
7781

7882
plotStarsOnGrid(stars);
7983

8084
let j = 0;
8185
while (j < maxSteps) {
82-
let [minPx, maxPx, minPy, maxPy] = [stars[0][0], stars[0][0], stars[0][1], stars[0][1]];
86+
let [minPx, maxPx, minPy, maxPy] = [
87+
stars[0][0],
88+
stars[0][0],
89+
stars[0][1],
90+
stars[0][1],
91+
];
8392

8493
const drawn = new Set();
8594
stars.forEach(([x, y]) => {
@@ -103,81 +112,119 @@ const findMessage = (rows) => {
103112
});
104113

105114
console.log(minPx, maxPx, minPy, maxPy);
106-
if ((maxPx - minPx < maxDistance) && (maxPy - minPy < maxDistance)) {
115+
if (maxPx - minPx < maxDistance && maxPy - minPy < maxDistance) {
107116
console.log(j);
108117
plotStarsOnGrid(stars);
109118
}
110119
stars = calculateNextStarState(stars);
111120

112121
j += 1;
113122
}
114-
115123
};
116124

117125
const findTheMessage = (rows) => {
118126
const points = rows.map((row) => {
119127
/* eslint-disable-next-line max-len */
120-
const [, x, y, xVel, yVel] = row.match(/position=<\s?(-?\d+), \s?(-?\d+)> velocity=<\s?(-?\d+), \s?(-?\d+)>/).map(v => +v);
128+
const [, x, y, xVel, yVel] = row
129+
.match(
130+
/position=<\s?(-?\d+), \s?(-?\d+)> velocity=<\s?(-?\d+), \s?(-?\d+)>/,
131+
)
132+
.map((v) => +v);
121133
return { x, y, xVel, yVel };
122134
});
123135

124136
let lastArea = Infinity;
125137

126-
let minX = Math.min.apply(null, points.map(p => p.x));
127-
let maxX = Math.max.apply(null, points.map(p => p.x));
128-
let minY = Math.min.apply(null, points.map(p => p.y));
129-
let maxY = Math.max.apply(null, points.map(p => p.y));
138+
let minX = Math.min.apply(
139+
null,
140+
points.map((p) => p.x),
141+
);
142+
let maxX = Math.max.apply(
143+
null,
144+
points.map((p) => p.x),
145+
);
146+
let minY = Math.min.apply(
147+
null,
148+
points.map((p) => p.y),
149+
);
150+
let maxY = Math.max.apply(
151+
null,
152+
points.map((p) => p.y),
153+
);
130154

131155
let currentArea = (maxX - minX) * (maxY - minY);
132156

133157
let time = -1;
134-
while(currentArea < lastArea) {
158+
while (currentArea < lastArea) {
135159
lastArea = currentArea;
136160

137161
time += 1;
138-
for(let point of points) {
162+
for (let point of points) {
139163
point.x += point.xVel;
140164
point.y += point.yVel;
141165
}
142166

143-
minX = Math.min.apply(null, points.map(p => p.x));
144-
maxX = Math.max.apply(null, points.map(p => p.x));
145-
minY = Math.min.apply(null, points.map(p => p.y));
146-
maxY = Math.max.apply(null, points.map(p => p.y));
167+
minX = Math.min.apply(
168+
null,
169+
points.map((p) => p.x),
170+
);
171+
maxX = Math.max.apply(
172+
null,
173+
points.map((p) => p.x),
174+
);
175+
minY = Math.min.apply(
176+
null,
177+
points.map((p) => p.y),
178+
);
179+
maxY = Math.max.apply(
180+
null,
181+
points.map((p) => p.y),
182+
);
147183

148184
currentArea = (maxX - minX) * (maxY - minY);
149185
}
150186

151-
for(let i = 0; i < 1; i++) {
152-
for(let point of points) {
187+
for (let i = 0; i < 1; i++) {
188+
for (let point of points) {
153189
point.x -= point.xVel;
154190
point.y -= point.yVel;
155191
}
156192
}
157193

158-
minX = Math.min.apply(null, points.map(p => p.x));
159-
maxX = Math.max.apply(null, points.map(p => p.x));
160-
minY = Math.min.apply(null, points.map(p => p.y));
161-
maxY = Math.max.apply(null, points.map(p => p.y));
194+
minX = Math.min.apply(
195+
null,
196+
points.map((p) => p.x),
197+
);
198+
maxX = Math.max.apply(
199+
null,
200+
points.map((p) => p.x),
201+
);
202+
minY = Math.min.apply(
203+
null,
204+
points.map((p) => p.y),
205+
);
206+
maxY = Math.max.apply(
207+
null,
208+
points.map((p) => p.y),
209+
);
162210

163211
let grid = [];
164-
for(let x = 0; x <= maxX - minX; x++) {
212+
for (let x = 0; x <= maxX - minX; x++) {
165213
grid.push([]);
166214
}
167215

168-
169-
for(let point of points) {
216+
for (let point of points) {
170217
grid[point.x - minX][point.y - minY] = true;
171218
}
172219

173220
let letterMaps = [];
174221

175-
for(let i = 0; i < maxX - minX; i+=8) {
222+
for (let i = 0; i < maxX - minX; i += 8) {
176223
let letterMap = [];
177224

178-
for(let y = 0; y <= maxY - minY; y++) {
225+
for (let y = 0; y <= maxY - minY; y++) {
179226
letterMap.push([]);
180-
for(let x = 0; x < 6; x++) {
227+
for (let x = 0; x < 6; x++) {
181228
letterMap[y].push(!!grid[x + i][y]);
182229
}
183230
}
@@ -189,10 +236,10 @@ const findTheMessage = (rows) => {
189236
let letterLines = file.trim().split('\n');
190237

191238
let letterData = {};
192-
while(letterLines.length) {
239+
while (letterLines.length) {
193240
let char = letterLines.shift();
194241
let d = [];
195-
for(let y = 0; y < 10; y++) {
242+
for (let y = 0; y < 10; y++) {
196243
let line = letterLines.shift();
197244
d.push([].map.call(line, (c) => c === '#'));
198245
}
@@ -201,11 +248,11 @@ const findTheMessage = (rows) => {
201248

202249
let result = '';
203250

204-
letterLoop: for(let letter of letterMaps) {
205-
charLoop: for(let char in letterData) {
206-
for(let x = 0; x < letterData[char].length; x++) {
207-
for(let y = 0; y < letterData[char][x].length; y++) {
208-
if(letter[x][y] !== letterData[char][x][y]) {
251+
letterLoop: for (let letter of letterMaps) {
252+
charLoop: for (let char in letterData) {
253+
for (let x = 0; x < letterData[char].length; x++) {
254+
for (let y = 0; y < letterData[char][x].length; y++) {
255+
if (letter[x][y] !== letterData[char][x][y]) {
209256
continue charLoop;
210257
}
211258
}

2018/14/debug.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const printDebug = (elves, scores, debug) => {
66
const parenthesis = elves[0].index;
77
const squareBrackets = elves[1].index;
88
const string = scores.reduce((str, score, index) => {
9-
109
if (index === parenthesis || index === squareBrackets) {
1110
if (index === parenthesis) {
1211
str += '(';
@@ -33,7 +32,6 @@ const printDebug = (elves, scores, debug) => {
3332
str += ' ';
3433
}
3534

36-
3735
return str;
3836
}, '');
3937
console.log(string);

2018/14/receipes.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
/* eslint-disable */
12
const { printDebug, printTotal } = require('./debug');
23

3-
const toArray = number => number.toString().split('');
4-
const updatePositions = (elves, scores) => elves.map(({ index, score }) => {
5-
const newIndex = (index + 1 + score) % scores.length;
6-
return { index: newIndex, score: +scores[newIndex] };
7-
});
4+
const toArray = (number) => number.toString().split('');
5+
const updatePositions = (elves, scores) =>
6+
elves.map(({ index, score }) => {
7+
const newIndex = (index + 1 + score) % scores.length;
8+
return { index: newIndex, score: +scores[newIndex] };
9+
});
810

911
const findScore = (input, steps, debug) => {
1012
let scores = toArray(input);
@@ -24,7 +26,6 @@ const findScore = (input, steps, debug) => {
2426
const total = [];
2527

2628
while (scores.length < steps + 10) {
27-
2829
const sum = elves.reduce((sum, elf) => {
2930
sum += parseInt(elf.score, 10);
3031
return sum;
@@ -38,18 +39,17 @@ const findScore = (input, steps, debug) => {
3839

3940
printTotal(total, debug);
4041
return scores.slice(steps, steps + 10).join('');
41-
4242
};
4343

4444
const testa = () => {
45-
let input = 880751;
46-
let recipes = [3, 7];
45+
const input = 880751;
46+
const recipes = [3, 7];
4747
let e1 = 0;
4848
let e2 = 1;
4949

5050
while (recipes.length <= input + 10) {
51-
let sum = recipes[e1] + recipes[e2];
52-
for (let ch of sum.toString().split('')) {
51+
const sum = recipes[e1] + recipes[e2];
52+
for (const ch of sum.toString().split('')) {
5353
recipes.push(parseInt(ch, 10));
5454
}
5555
e1 += 1 + recipes[e1];
@@ -66,13 +66,13 @@ const testa = () => {
6666
};
6767

6868
const testa2 = () => {
69-
let recipes = [3, 7];
69+
const recipes = [3, 7];
7070
let e1 = 0;
7171
let e2 = 1;
7272

7373
while (recipes.length <= 30000000) {
74-
let sum = recipes[e1] + recipes[e2];
75-
for (let ch of sum.toString().split('')) {
74+
const sum = recipes[e1] + recipes[e2];
75+
for (const ch of sum.toString().split('')) {
7676
recipes.push(parseInt(ch, 10));
7777
}
7878
e1 += 1 + recipes[e1];
@@ -81,20 +81,20 @@ const testa2 = () => {
8181
e2 %= recipes.length;
8282
}
8383

84-
let input = `880751`;
84+
const input = `880751`;
8585
for (let i = 0; i < recipes.length - 6; ++i) {
86-
if (recipes[i] == input[0]
87-
&& recipes[i+1] == input[1]
88-
&& recipes[i+2] == input[2]
89-
&& recipes[i+3] == input[3]
90-
&& recipes[i+4] == input[4]
91-
&& recipes[i+5] == input[5]) {
86+
if (
87+
recipes[i] == input[0] &&
88+
recipes[i + 1] == input[1] &&
89+
recipes[i + 2] == input[2] &&
90+
recipes[i + 3] == input[3] &&
91+
recipes[i + 4] == input[4] &&
92+
recipes[i + 5] == input[5]
93+
) {
9294
console.log(i);
9395
break;
9496
}
9597
}
96-
}
97-
98-
98+
};
9999

100100
module.exports = { findScore, testa, testa2 };

2018/14/solve.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ const solve1 = () => {
55
console.log(findScore(880751, 10, true));
66
};
77

8-
98
solve1();
10-
//solve2();
9+
// solve2();
1110
// 5138216212
1211
// 88075116
1312
// 88075116815138216212

2018/14/test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const { findScore, testa, testa2 } = require('./receipes');
1+
const { findScore, testa2 } = require('./receipes');
22

33
describe('it should solve day 14', () => {
4-
54
describe('it should solve part 1', () => {
65
it('it should get correct answer after 5 steps', () => {
76
expect(findScore(37, 5, true)).toEqual('0124515891');
@@ -28,6 +27,5 @@ describe('it should solve day 14', () => {
2827
it('should solve the test case', () => {
2928
expect().toEqual(325);
3029
});
31-
});*/
32-
30+
}); */
3331
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy