···11+import { assert } from "https://deno.land/std@0.208.0/assert/assert.ts";
22+13if (import.meta.main) {
24 const input = (
35 await Deno.readFile("input").then((bytes) =>
···810}
9111012export function answer(input: string): number {
1111- console.log(input);
1212- return 42;
1313+ const [raceDuration, record] = input
1414+ .split("\n")
1515+ .map((l) => parseInt(l.split(/\s+/).slice(1).join("")));
1616+ const [min, max] = minMaxHoldsToWin(raceDuration, record);
1717+ return max - min + 1;
1818+}
1919+2020+function minMaxHoldsToWin(
2121+ raceDuration: number,
2222+ record: number,
2323+): [number, number] {
2424+ let min = 0;
2525+ let max = 0;
2626+ for (let hold = 0; hold < raceDuration; hold++) {
2727+ const distance = hold * (raceDuration - hold);
2828+ if (min === 0 && distance > record) min = hold;
2929+ if (min !== 0 && distance > record) max = hold;
3030+ if (min !== 0 && max !== 0 && distance < record) break;
3131+ }
3232+ return [min, max];
1333}
+31-2
2023/day06/puzzle.md
···48484949Determine the number of ways you could beat the record in each race. *What do you get if you multiply these numbers together?*
50505151-To begin, [get your puzzle input](6/input).
5151+Your puzzle answer was `114400`.
5252+5353+The first half of this puzzle is complete! It provides one gold star: \*
5454+5555+\--- Part Two ---
5656+----------
5757+5858+As the race is about to start, you realize the piece of paper with race times and record distances you got earlier actually just has very bad [kerning](https://en.wikipedia.org/wiki/Kerning). There's really *only one race* - ignore the spaces between the numbers on each line.
5959+6060+So, the example from before:
6161+6262+```
6363+Time: 7 15 30
6464+Distance: 9 40 200
6565+6666+```
6767+6868+...now instead means this:
6969+7070+```
7171+Time: 71530
7272+Distance: 940200
7373+7474+```
7575+7676+Now, you have to figure out how many ways there are to win this single race. In this example, the race lasts for *`71530` milliseconds* and the record distance you need to beat is *`940200` millimeters*. You could hold the button anywhere from `14` to `71516` milliseconds and beat the record, a total of `*71503*` ways!
7777+7878+*How many ways can you beat the record in this one much longer race?*
52795380Answer:
54815555-You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Wait+For+It%22+%2D+Day+6+%2D+Advent+of+Code+2023&url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F6&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle.8282+Although it hasn't changed, you can still [get your puzzle input](6/input).
8383+8484+You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22Wait+For+It%22+%2D+Day+6+%2D+Advent+of+Code+2023&url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F6&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle.