this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

part 2 done!

+57 -6
+22 -2
2023/day06/part2.ts
··· 1 + import { assert } from "https://deno.land/std@0.208.0/assert/assert.ts"; 2 + 1 3 if (import.meta.main) { 2 4 const input = ( 3 5 await Deno.readFile("input").then((bytes) => ··· 8 10 } 9 11 10 12 export function answer(input: string): number { 11 - console.log(input); 12 - return 42; 13 + const [raceDuration, record] = input 14 + .split("\n") 15 + .map((l) => parseInt(l.split(/\s+/).slice(1).join(""))); 16 + const [min, max] = minMaxHoldsToWin(raceDuration, record); 17 + return max - min + 1; 18 + } 19 + 20 + function minMaxHoldsToWin( 21 + raceDuration: number, 22 + record: number, 23 + ): [number, number] { 24 + let min = 0; 25 + let max = 0; 26 + for (let hold = 0; hold < raceDuration; hold++) { 27 + const distance = hold * (raceDuration - hold); 28 + if (min === 0 && distance > record) min = hold; 29 + if (min !== 0 && distance > record) max = hold; 30 + if (min !== 0 && max !== 0 && distance < record) break; 31 + } 32 + return [min, max]; 13 33 }
+31 -2
2023/day06/puzzle.md
··· 48 48 49 49 Determine the number of ways you could beat the record in each race. *What do you get if you multiply these numbers together?* 50 50 51 - To begin, [get your puzzle input](6/input). 51 + Your puzzle answer was `114400`. 52 + 53 + The first half of this puzzle is complete! It provides one gold star: \* 54 + 55 + \--- Part Two --- 56 + ---------- 57 + 58 + 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. 59 + 60 + So, the example from before: 61 + 62 + ``` 63 + Time: 7 15 30 64 + Distance: 9 40 200 65 + 66 + ``` 67 + 68 + ...now instead means this: 69 + 70 + ``` 71 + Time: 71530 72 + Distance: 940200 73 + 74 + ``` 75 + 76 + 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! 77 + 78 + *How many ways can you beat the record in this one much longer race?* 52 79 53 80 Answer: 54 81 55 - 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. 82 + Although it hasn't changed, you can still [get your puzzle input](6/input). 83 + 84 + 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.
+4 -2
2023/day06/test.ts
··· 10 10 }); 11 11 12 12 Deno.test("part2", () => { 13 - const examples = ["abc", "def"].join("\n"); 14 - assertEquals(p2.answer(examples), 42); 13 + const examples = ["Time: 7 15 30", "Distance: 9 40 200"].join( 14 + "\n", 15 + ); 16 + assertEquals(p2.answer(examples), 71503); 15 17 });