Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kevinahn7/6672e6fb3ea1cbee1ae64ba71bb1e11c to your computer and use it in GitHub Desktop.

Select an option

Save kevinahn7/6672e6fb3ea1cbee1ae64ba71bb1e11c to your computer and use it in GitHub Desktop.
https://adventofcode.com/2018/day/3
#1 @ 338,764: 20x24
#2 @ 80,667: 12x26
#3 @ 625,36: 17x22
#4 @ 196,235: 25x13
#5 @ 610,700: 25x21
#6 @ 590,831: 20x13
#7 @ 253,201: 29x22
#8 @ 921,577: 15x13
#9 @ 495,85: 20x19
#10 @ 397,589: 17x22
#1 @ 1,3: 4x4
#2 @ 3,1: 4x4
#3 @ 5,5: 2x2
1000x1000
........
...2222.
...2222.
.11XX22.
.11XX22.
.111133.
.111133.
........
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
function noMatterHowYouSliceIt(string) {
let resultObject = {};
let resultCounter = 0;
let stringArray = string.split("#");
for (let i = 0; i < stringArray.length; i++) {
stringArray[i] = stringArray[i].split(" "); // ['10', '@', '397,589:', '17x22']
stringArray[i][2] = stringArray[i][2].slice(0, stringArray[i][2].length - 1).split(","); // ['10', '@', ['397', '598'], '17x22']
stringArray[i][3] = stringArray[i][3]/split("x"); // ['10', '@', ['397', '598'], ['17', '22']
let square = {
x: stringArray[i][2][0],
y: stringArray[i][2][1],
width: stringArray[i][3][0],
height: stringArray[i][3][1],
};
let startingPoint = 1;
let coveredNumbers = [];
//startingPoint += stringArray[i][2][0] + (stringArray[i][2][1] * 1000);
startingPoint += square.x + (square.y * 1000);
for (let j = 0; j < stringArray[i][3][1]; j++) {
let counter = startingPoint + (j * 1000)
for (let k = 0; k < stringArray[i][3][0]; k++) {
coveredNumbers.push(counter + k)
}
}
for (let l = 0; l < coveredNumbers.length; l++) {
if (result[coveredNumbers[l]]) {
result[coveredNumbers[l]]++;
} else {
result[coveredNumbers[l]] = 1;
}
}
}
for (key in resultObject) {
if (resultObject.key > 1) {
resultCounter++;
}
}
return resultCounter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment