Created
December 17, 2021 05:12
-
-
Save bluepichu/454aecbadef9f51d96559404a9414c6e to your computer and use it in GitHub Desktop.
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
import { Advent, int } from "advent"; | |
const { compute, computeCheck } = await Advent({ day: 17 }); | |
compute(async (input) => { | |
// const data = input.tokens(/,/).map(int); | |
// const data = input.ints(); | |
const x1 = 32 | |
const x2 = 65 | |
const y1 = -225 | |
const y2 = -177 | |
function check(vx: number, vy: number) { | |
let x = 0; | |
let y = 0; | |
let maxY = 0; | |
while (x < x2 && y >= y1) { | |
x += vx; | |
y += vy; | |
vx -= Math.sign(vx); | |
vy--; | |
maxY = Math.max(maxY, y); | |
if (x >= x1 && y >= y1 && x <= x2 && y <= y2) { | |
return maxY; | |
} | |
} | |
return undefined; | |
} | |
let best = -Infinity; | |
let count = 0; | |
for (let vx = -1000; vx <= 1000; vx++) { | |
for (let vy = -1000; vy <= 1000; vy++) { | |
const y = check(vx, vy); | |
if (y !== undefined) { | |
count++; | |
} | |
if (y !== undefined && y > best) { | |
best = y; | |
} | |
} | |
} | |
return count; | |
},2); | |
// computeCheck(async function* (input) { | |
// yield 0; | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment