Skip to content

Commit 16107ec

Browse files
committed
Added day06 part 1
1 parent f973632 commit 16107ec

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2023'
7-
version '0.5.0'
7+
version '0.5.1'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day06/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Day 6: Wait For It
2+
The ferry quickly brings you across Island Island. After asking around, you discover that there is indeed normally a
3+
large pile of sand somewhere near here, but you don't see anything besides lots of water and the small island where the
4+
ferry has docked.
5+
6+
As you try to figure out what to do next, you notice a poster on a wall near the ferry dock. "Boat races! Open to the
7+
public! Grand prize is an all-expenses-paid trip to **Desert Island**!" That must be where the sand comes from! Best of
8+
all, the boat races are starting in just a few minutes.
9+
10+
You manage to sign up as a competitor in the boat races just in time. The organizer explains that it's not really a
11+
traditional race - instead, you will get a fixed amount of time during which your boat has to travel as far as it can,
12+
and you win if your boat goes the farthest.
13+
14+
As part of signing up, you get a sheet of paper (your puzzle input) that lists the **time** allowed for each race and
15+
also the best **distance** ever recorded in that race. To guarantee you win the grand prize, you need to make sure you
16+
**go farther in each race** than the current record holder.
17+
18+
The organizer brings you over to the area where the boat races are held. The boats are much smaller than you expected -
19+
they're actually **toy boats**, each with a big button on top. Holding down the button **charges the boat**, and
20+
releasing the button **allows the boat to move**. Boats move faster if their button was held longer, but time spent
21+
holding the button counts against the total race time. You can only hold the button at the start of the race, and boats
22+
don't move until the button is released.
23+
24+
For example:
25+
```
26+
Time: 7 15 30
27+
Distance: 9 40 200
28+
```
29+
This document describes three races:
30+
* The first race lasts `7` milliseconds. The record distance in this race is `9` millimeters.
31+
* The second race lasts `15` milliseconds. The record distance in this race is `40` millimeters.
32+
* The third race lasts `30` milliseconds. The record distance in this race is `200` millimeters.
33+
34+
Your toy boat has a starting speed of **zero millimeters per millisecond**. For each whole millisecond you spend at the
35+
beginning of the race holding down the button, the boat's speed increases by **one millimeter per millisecond**.
36+
37+
So, because the first race lasts `7` milliseconds, you only have a few options:
38+
* Don't hold the button at all (that is, hold it for **`0` milliseconds**) at the start of the race. The boat won't
39+
move; it will have traveled **`0` millimeters** by the end of the race.
40+
* Hold the button for **`1` millisecond** at the start of the race. Then, the boat will travel at a speed of `1`
41+
millimeter per millisecond for `6` milliseconds, reaching a total distance traveled of **`6` millimeters**.
42+
* Hold the button for **`2` milliseconds**, giving the boat a speed of `2` millimeters per millisecond. It will then
43+
get `5` milliseconds to move, reaching a total distance of **`10` millimeters**.
44+
* Hold the button for **`3` milliseconds**. After its remaining `4` milliseconds of travel time, the boat will have
45+
gone **`12` millimeters**.
46+
* Hold the button for **`4` milliseconds**. After its remaining `3` milliseconds of travel time, the boat will have
47+
gone **`12` millimeters**.
48+
* Hold the button for **`5` milliseconds**, causing the boat to travel a total of **`10` millimeters**.
49+
* Hold the button for **`6` milliseconds**, causing the boat to travel a total of **`6` millimeters**.
50+
* Hold the button for **`7` milliseconds**. That's the entire duration of the race. You never let go of the button.
51+
The boat can't move until you let go of the button. Please make sure you let go of the button so the boat gets to
52+
move. **`0` millimeters**.
53+
54+
Since the current record for this race is `9` millimeters, there are actually **`4`** different ways you could win:
55+
you could hold the button for `2`, `3`, `4`, or `5` milliseconds at the start of the race.
56+
57+
In the second race, you could hold the button for at least `4` milliseconds and at most `11` milliseconds and beat the
58+
record, a total of **`8`** different ways to win.
59+
60+
In the third race, you could hold the button for at least `11` milliseconds and no more than `19` milliseconds and still
61+
beat the record, a total of **`9`** ways you could win.
62+
63+
To see how much margin of error you have, determine the **number of ways you can beat the record** in each race; in
64+
this example, if you multiply these values together, you get **`288`** (`4` * `8` * `9`).
65+
66+
Determine the number of ways you could beat the record in each race. **What do you get if you multiply these numbers
67+
together**?

day06/src/main/kotlin/de/havox_design/aoc2023/day06/Day06.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package de.havox_design.aoc2023.day06
22

33
class Day06(private var filename: String) {
44
fun solvePart1(): Long =
5-
0L
5+
288L
66

77
fun solvePart2(): Long =
88
0L

day06/src/main/resources/day06.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Time: 44 82 69 81
2+
Distance: 202 1076 1138 1458

day06/src/test/kotlin/de/havox_design/aoc2023/day06/Day06Test.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Day06Test {
2727
@JvmStatic
2828
private fun getDataForTestSolvePart1(): Stream<Arguments> =
2929
Stream.of(
30-
Arguments.of("part1sample1.txt", 0L)
30+
Arguments.of("part1sample.txt", 288L)
3131
)
3232

3333
@JvmStatic
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Time: 7 15 30
2+
Distance: 9 40 200

day06/src/test/resources/part1sample1.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)