-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { intcodeComputer } from '../05/day05.helper'; | ||
|
||
export const isTractorBeam = ( | ||
nums: number[], | ||
x: number, | ||
y: number | ||
): boolean => { | ||
return intcodeComputer([...nums], [x, y]) === 1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { day19p1 } from './p1'; | ||
import { day19p2 } from './p2'; | ||
import { getPuzzle } from '@utilities/getPuzzle'; | ||
|
||
const { input } = getPuzzle(__dirname); | ||
|
||
describe('Day 19 Puzzle', () => { | ||
test('Part 1 Input', () => { | ||
expect(day19p1(input)).toBe(192); | ||
}); | ||
|
||
test('Part 2 Input', () => { | ||
expect(day19p2(input)).toBe(8_381_082); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
109,424,203,1,21101,11,0,0,1106,0,282,21102,18,1,0,1105,1,259,1201,1,0,221,203,1,21101,0,31,0,1105,1,282,21102,1,38,0,1106,0,259,21001,23,0,2,22101,0,1,3,21102,1,1,1,21101,57,0,0,1106,0,303,1202,1,1,222,21002,221,1,3,20102,1,221,2,21101,259,0,1,21102,1,80,0,1105,1,225,21101,83,0,2,21101,91,0,0,1105,1,303,2102,1,1,223,20102,1,222,4,21102,259,1,3,21101,225,0,2,21101,225,0,1,21102,1,118,0,1105,1,225,20102,1,222,3,21101,0,51,2,21102,1,133,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21102,1,148,0,1106,0,259,1201,1,0,223,21002,221,1,4,21002,222,1,3,21101,13,0,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,195,1,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21101,0,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2102,1,-4,249,21202,-3,1,1,21202,-2,1,2,22102,1,-1,3,21101,0,250,0,1105,1,225,22102,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22101,0,-2,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22101,0,-2,3,21101,0,343,0,1106,0,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21202,-4,1,1,21102,384,1,0,1106,0,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22101,0,1,-4,109,-5,2105,1,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getPuzzle } from '@utilities/getPuzzle'; | ||
import { run } from '@utilities/run'; | ||
import { isTractorBeam } from './day19.helper'; | ||
|
||
export const day19p1 = (input: string) => { | ||
const nums = input.split(',').map(Number); | ||
let count = 0; | ||
|
||
for (let y = 0; y < 50; y++) { | ||
for (let x = 0; x < 50; x++) { | ||
if (isTractorBeam(nums, x, y)) { | ||
count += 1; | ||
} | ||
} | ||
} | ||
|
||
return count; | ||
}; | ||
|
||
const input = getPuzzle(__dirname).input; | ||
run(() => day19p1(input)); // 192 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { getPuzzle } from '@utilities/getPuzzle'; | ||
import { run } from '@utilities/run'; | ||
import { isTractorBeam } from './day19.helper'; | ||
|
||
export const day19p2 = (input: string) => { | ||
const nums = input.split(',').map(Number); | ||
let found = false; | ||
let x = 50; | ||
let y = 50; | ||
const size = 100; | ||
|
||
while (!found) { | ||
x += 1; | ||
y = findLowestPoint(nums, x, y); | ||
|
||
if (y < size) continue; | ||
|
||
if (canShipFit(nums, x, y, size)) { | ||
found = true; | ||
} | ||
} | ||
|
||
return x * 10000 + (y - size + 1); | ||
}; | ||
|
||
const findLowestPoint = (nums: number[], x: number, y: number): number => { | ||
while (!isTractorBeam(nums, x, y) || isTractorBeam(nums, x, y + 1)) { | ||
y++; | ||
} | ||
|
||
return y; | ||
}; | ||
|
||
const canShipFit = ( | ||
nums: number[], | ||
x: number, | ||
y: number, | ||
size: number | ||
): boolean => { | ||
return ( | ||
isTractorBeam(nums, x + size - 1, y - size + 1) && | ||
isTractorBeam(nums, x, y - size + 1) && | ||
isTractorBeam(nums, x + size - 1, y) && | ||
isTractorBeam(nums, x, y) | ||
); | ||
}; | ||
|
||
const input = getPuzzle(__dirname).input; | ||
run(() => day19p2(input)); // 8381082 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters