Skip to content

Commit 10646d8

Browse files
committed
Added day07 part 1
1 parent 2c3b476 commit 10646d8

File tree

7 files changed

+1088
-3
lines changed

7 files changed

+1088
-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.6.0'
7+
version '0.6.1'
88

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

day07/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Day 7: Camel Cards
2+
Your all-expenses-paid trip turns out to be a one-way, five-minute ride in an
3+
[airship](https://en.wikipedia.org/wiki/Airship). (At least it's a **cool** airship!) It drops you off at the edge of a
4+
vast desert and descends back to Island Island.
5+
6+
"Did you bring the parts?"
7+
8+
You turn around to see an Elf completely covered in white clothing, wearing goggles, and riding a large
9+
[camel](https://en.wikipedia.org/wiki/Dromedary).
10+
11+
"Did you bring the parts?" she asks again, louder this time. You aren't sure what parts she's looking for; you're here
12+
to figure out why the sand stopped.
13+
14+
"The parts! For the sand, yes! Come with me; I will show you." She beckons you onto the camel.
15+
16+
After riding a bit across the sands of Desert Island, you can see what look like very large rocks covering half of the
17+
horizon. The Elf explains that the rocks are all along the part of Desert Island that is directly above Island Island,
18+
making it hard to even get there. Normally, they use big machines to move the rocks and filter the sand, but the
19+
machines have broken down because Desert Island recently stopped receiving the **parts** they need to fix the machines.
20+
21+
You've already assumed it'll be your job to figure out why the parts stopped when she asks if you can help. You agree
22+
automatically.
23+
24+
Because the journey will take a few days, she offers to teach you the game of **Camel Cards**. Camel Cards is sort of
25+
similar to [poker](https://en.wikipedia.org/wiki/List_of_poker_hands) except it's designed to be easier to play while
26+
riding a camel.
27+
28+
In Camel Cards, you get a list of **hands**, and your goal is to order them based on the **strength** of each hand. A
29+
hand consists of **five cards** labeled one of `A`, `K`, `Q`, `J`, `T`, `9`, `8`, `7`, `6`, `5`, `4`, `3`, or `2`. The
30+
relative strength of each card follows this order, where `A` is the highest and `2` is the lowest.
31+
32+
Every hand is exactly one **type**. From strongest to weakest, they are:
33+
* **Five of a kind**, where all five cards have the same label: `AAAAA`
34+
* **Four of a kind**, where four cards have the same label and one card has a different label: `AA8AA`
35+
* **Full house**, where three cards have the same label, and the remaining two cards share a different label: `23332`
36+
* **Three of a kind**, where three cards have the same label, and the remaining two cards are each different from any
37+
other card in the hand: `TTT98`
38+
* **Two pair**, where two cards share one label, two other cards share a second label, and the remaining card has a
39+
third label: `23432`
40+
* **One pair**, where two cards share one label, and the other three cards have a different label from the pair and
41+
each other: `A23A4`
42+
* **High card**, where all cards' labels are distinct: `23456`
43+
44+
Hands are primarily ordered based on type; for example, every **full house** is stronger than any **three of a kind**.
45+
46+
If two hands have the same type, a second ordering rule takes effect. Start by comparing the **first card in each
47+
hand**. If these cards are different, the hand with the stronger first card is considered stronger. If the first card
48+
in each hand have the **same label**, however, then move on to considering the **second card in each hand**. If they
49+
differ, the hand with the higher second card wins; otherwise, continue with the third card in each hand, then the
50+
fourth, then the fifth.
51+
52+
So, `33332` and `2AAAA` are both **four of a kind** hands, but `33332` is stronger because its first card is stronger.
53+
Similarly, `77888` and `77788` are both a full house, but `77888` is stronger because its third card is stronger (and
54+
both hands have the same first and second card).
55+
56+
To play Camel Cards, you are given a list of hands and their corresponding **bid** (your puzzle input). For example:
57+
```
58+
32T3K 765
59+
T55J5 684
60+
KK677 28
61+
KTJJT 220
62+
QQQJA 483
63+
```
64+
This example shows five hands; each hand is followed by its **bid** amount. Each hand wins an amount equal to its bid
65+
multiplied by its **rank**, where the weakest hand gets rank `1`, the second-weakest hand gets rank `2`, and so on up
66+
to the strongest hand. Because there are five hands in this example, the strongest hand will have rank `5` and its bid
67+
will be multiplied by `5`.
68+
69+
So, the first step is to put the hands in order of strength:
70+
* `32T3K` is the only **one pair** and the other hands are all a stronger type, so it gets rank **`1`**.
71+
* `KK677` and `KTJJT` are both **two pair**. Their first cards both have the same label, but the second card of `KK677`
72+
is stronger (`K` vs `T`), so `KTJJT` gets rank **`2`** and `KK677` gets rank **`3`**.
73+
* `T55J5` and `QQQJA` are both **three of a kind**. `QQQJA` has a stronger first card, so it gets rank **`5`** and
74+
`T55J5` gets rank **`4`**.
75+
76+
Now, you can determine the total winnings of this set of hands by adding up the result of multiplying each hand's bid
77+
with its rank (`765` * 1 + `220` * 2 + `28` * 3 + `684` * 4 + `483` * 5). So the **total winnings** in this example are
78+
**`6440`**.
79+
80+
Find the rank of every hand in your set. **What are the total winnings**?

day07/src/main/kotlin/de/havox_design/aoc2023/day07/Day07.kt

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

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

77
fun solvePart2(): Long =
88
0L

0 commit comments

Comments
 (0)