You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/bin/day7/README.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
# Day 7
2
2
## Input
3
-
You get a list of hands, and your goal is to order them based on the strength of each hand. A hand consists of five cards labeled one of `A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2`.
4
-
5
-
The relative strength of each card follows this order, where `A` is the highest and `2` is the lowest
3
+
You get a list of hands & bids pairs, and your goal is to order them based on the strength of each hand.
6
4
```
7
5
32T3K 765
8
6
T55J5 684
9
7
KK677 28
10
8
KTJJT 220
11
9
QQQJA 483
12
10
```
11
+
A hand consists of five cards labeled one of `A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2`. The relative strength of each card follows this order, where `A` is the highest and `2` is the lowest
13
12
Every hand is exactly one type. From strongest to weakest, they are:
14
13
15
14
***Five of a kind**, where all five cards have the same label: `AAAAA`
@@ -24,12 +23,13 @@ If two hands have the same type, a second ordering rule takes effect. Start by c
24
23
## Part 1: Output
25
24
Find the rank of every hand in your set and calculate the total winnings of this set of hands by adding up the result of multiplying each hand's bid with its rank
To find the type of hand, use a Hashmap to extract the counts for character in the string, then convert the Hashmap to a Vector and reverse sort it. Now you should have in reverse order all the unique cards and card frequency.
50
+
To find the type of hand, use a `Hashmap` to extract the frequency per character in the hand, then convert the `Hashmap` to a `Vector` and reverse sort it. Now you should have in reverse order all the unique cards and card frequency i.e. `[('A',2),('J',2),('2',1)]`
50
51
51
-
Hence the types are derived from two values (a) number of unique cards& (b) the highest card freq
52
+
Hence, the types are derived from two values (a) number of unique cards; `array.len()`& (b) the highest card freq; `array[0].freq`
52
53
```
53
-
match array_length {
54
+
match array.len() {
54
55
1 => HandType::FiveOfAKind,
55
56
2 if array[0].freq ==4 => HandType::FourOfAKind,
56
57
2 => HandType::FullHouse,
@@ -65,5 +66,5 @@ The Joker card affects the two key parameters like this
1.`JJ123`', hence if Joker is the most frequency card you have to pick the card with `highest card freq` coming after the joker
69
-
2.'`JJJJ`' ignore the Joker logic
69
+
1.`JJ123`, hence if the Joker is the most frequent card, you have to pick the next in order card that has the highest card frequency after the joker one.
0 commit comments