For part 2, how is J345A sorted below 2345J? both are high cards, so J should make them both single pairs, and it should come down to card strength. 2 is weaker than J, so shouldn't J345A be better than 2345J?
cards are now the weakest individual cards, weaker even than
2
I DID miss that, thank you. this section > J is always treated as J, not the card it's pretending to be: JKKK2 is weaker than QQQQ2 because J is weaker than Q.
led me to believe that J remains as it was, which was always weaker than Q.
Same :Dd In the beginning I was doing with value of J being the lowest, but then I gradually forgot it. Then I read "J is always treated as J, not the card it's pretending to be: JKKK2 is weaker than QQQQ2 because J is weaker than Q." and automatically thought that J stays as it is 10<J<Q. I spent 1 hour searching for mistakes and it came out I only had to delete 1 letter
I treated J345A as high card instead of pair, as well as AJJ94treated as pair instead of three of a kind.
Sometimes it would be nice to have more original examples in task descriptions as this was really lacking. Not sure if that was language barrier or what.
Thanks, it helped me. When I was reading part 2 I just added J to the end "AKQJT98765432" => "AKQJT98765432J" without checking that J was already here.
Thanks !! this helped me i was finally able to solve the problem !! I was searching for some edge case i might have missed for past 1-2 hrs and now i noticed i didn't removed the first J in string lol
I used an enum class as well, but (in python), I was just able to change the value associated with the J to 1 i.o. 11 and then it sorted correctly again.
EDIT: No longer stumped! Forgot to check if the jokers were already used as stand if for other cards before considering them as standalone cards. So the error was discovered when two jokers could both make a three of a kind with another card as well as be a pair by themselves, making full house when it should'nt be.
[Part 2] I am stumped, I get the correct order and output on your test case as well as any i've made myself. And I have quadruple checked that I have the correct input, but still my answer is just wrong.
Sorry for the terrible code but essentially for part 2 I did the change in the cards list, and in the getType function, pop 'J' before finding the most common elem, and then add +1 to its count for each 'J', and then add the count of 'J's back before determining the type. (as int 1-7 -> five of a kind - high card respectively) The fix was to simply multiply `jcount` with `not maxCard`, both of them are non-zero only when there both are `J`s in the hand and there is no card they have been used to boost:
import sys
from collections import Counter
from functools import cmp_to_key
cards = ['A','K','Q','T','9','8','7','6','5','4','3','2','J']
def getType(hand: list[str]) -> int:
count = Counter(hand)
jcount = count.pop('J', 0)
maxCard = max(count, key=count.get, default='')
for _ in range(jcount):
count[maxCard] = min(count[maxCard]+1, 5)
count = sorted(list(count.values())+[jcount*(not maxCard)], reverse=True)
match count:
case [5,*_]: return 1
case [4,*_]: return 2
case [3,2,*_]: return 3
case [3,_,*_]: return 4
case [2,2,*_]: return 5
case [2,*_]: return 6
case _: return 7
def compare(hand1: list[str], hand2: list[str]) -> int:
h1, h2 = hand1[0], hand2[0]
type1, type2 = getType(h1), getType(h2)
if type1 != type2:
return type2-type1
for a, b in zip(h1, h2):
if cards.index(a) < cards.index(b):
return 1
elif cards.index(a) > cards.index(b):
return -1
return 0
ls = [x.split() for x in sys.stdin.readlines()]
hands = sorted(ls, key=cmp_to_key(compare))
ans = 0
for i,bet in enumerate([int(x[1]) for x in hands]):
ans += (i+1)*bet
print(ans)
This is Python, right? Have you considered using from collections import Counter? This easily gives you all of the counts as well as the sorted counts by doing Counter(hand).most(common).
This is python yep sorry forgot to label it. Sorted counts with Counter would definitely easy up on the complicated code, gonna use that instead, thanks!
Different clients and web interfaces can render spoiler tags differently. The only way to ensure that tags are rendered correctly for everyone is to not have any spaces between the exclamation points and the content. Some of your spoiler tags didn't render correctly for me on Old Reddit because there were spaces between the >! and the spoiler text.
So this will work work everywhere:
>!Spoiler!<
These might work in some places, but are not guaranteed to work everywhere:
>! Spoiler!<
>!Spoiler !<
>! Spoiler !<
For reference, here's what each one looks like rendered:
Unfortunately, spoiler tags can't span multiple paragraphs. You have to add a new set of tags for each paragraph, and the readers will have to click/tap on each separate line to reveal it.
However! In some testing just now, I figured out a workaround. If you end a line with two spaces, Reddit will put a line break there and will consider the next bit of text to be part of the same paragraph. You can fake a paragraph by putting in two consecutive line breaks. (This might interfere with some subreddits' custom CSS, but it seems to work correctly here, at least.) Reddit will ignore two spaces by themselves on a line, but you can work around that by starting a line with a character that will be invisible to the reader, but which Reddit doesn't treat as a space. A nonbreaking space seems to do the trick.
So here's a proof of concept, first in code, and then in execution. (I'm using “␣” to show the spaces in the code example.):
Always good to see more sample inputs for challenges. Sadly I'm at work all day today but this will definitely be useful this evening when I get to Day 7!
... and 12 hours later it was useful! I bashed my code around until it passed this sample test, and then it passed on the real data first time. Thanks again.
Helpful input tweak that helped me identify a bug in my Four of a Kind/Full House logic. Not all bids are prime but if properly sorted should still be in order .
I'm such a freaking idiot. I was pulling my hair out trying to figure out why I was doing ok with the test set but not the full set. I wrote the logic as actual poker logic - way more work than needed and it was wrong.
Nice, I did the same thing for debugging for part 2 and wanted to share my list but then saw your post. I guess I'll drop it here as a comment instead.
I just assume everyone can sort on card strength well enough when you reach part 2, so I only made a list to make sure you'd get the right hand strength:
The bids correspond to the hand strength where 1 is high card, 2 is one pair, 3 is two pair, 4 is three of a kind, 5 is full house, 6 is four of a kind, 7 is five of a kind.
Note that this is not the order these should be sorted into, because I ignored card strength. I just made a list to get the correct hand strength.
Edit: freaking Reddit Fancy Editor messes up code blocks if you paste in your code
Edit: Emphasised this is only for part 2 and only focuses on hand strength and ignores card strength
Edit: extended the five of a kind list for completion
I only made this list to make sure you'd get the right hand strength, because when you reach part 2, I assume you can sort on card strength yourself well enough.
But maybe I didn't make it clear enough that this list is only for part 2, sorry if that was confusing, I'll edit my post a bit.
Sorry, my bad! I was desperately hoping that my solution wasn't working because JJJJJ had priority over 11111 and that I had misunderstood the problem 😂
What I learned from doing this is that you can't make Two Pair with a Joker, and Full House can only be done with 1 Joker or no Jokers.
My mistake was trying to take jokers into account everywhere, but I after this I realised that I didn't need to change anything to find Two Pair and finding Full House with jokers was easy as well: just look for Two Pair and a Joker.
u/LxsterGames - are you able to provide any insight to me? I used your new input date (big thank you - it helped me catch some issues that were existing in my code) - I have since fixed my code. With your input - it is generating the expected output for part 1: 6592, however, my code is still failing for the actual puzzle input. I've walked through it many times and I'm at a loss for what it could be. My ranking and bids line up with what you have there.
Thank you so much for this... Reading your output made me realize I made a terrible mistake in reading the instructions... Even if the point about J cards being the weakest is very visible...
Thanks a ton. I wasn't handling five-of-a-kinds right and wondering wtf went wrong with my actual input.
I was saving the numbers of each card in a sorted tuple, i.e. full house is (2,3), but then comparing the tuple (5,) to the integer (5) in my logic and thinking it was a high card by default. Sometimes I hate python.
I was getting a Part2 wrong result, albeit the AoC example returned the right value. Your test was most helpful in spotting a bug that would have taken me a long time to discover
So I have a small issue. My part 1 solution works for the original test input, for your test input, but doesn't work for the actual input (the sum is too high) and I have no clue why.
Thank you, it made me find an error. Unfortunately my answer is still wrong even though I get the correct output from your example. Even with a full house like KKJAA. This is so frustrating :/
Okay,I'm officially confused, my solution matches your output for part2 but when i run it through actual input something is still wrong. Guess it's back to the drawing board.
This helped me track down a bug in my Part 1 where I was failing to sort on the 5th card in "high card" hands.
I'm working in Python for the first time this year; lesson learned on how "range" is *exclusive*, not inclusive, on the second argument. That is, to get the set of values {0, 1, 2, 3, 4}, you need to do range(0, 5), not range(0, 4).
what the hell. I have the correct order, and the same sum at the end than fort part 1, and I still don't get your result for part 2. The method to calculate the bids doesn't change right ?
I spent a lot of time looking for problems, only to realise that three of a kind of jokers, means you have four or a kind. Perhaps add that case to your sample input as well?
The examples this year are making it extremely hard to work out the edge-cases that are being missed when putting through the full input.
I realised that I was adding the Joker counts to themselves, which was resulting in me getting lower than expected values. The Q2KJJ test case helped point that out for me
Thank you very much for this, its greatly appricated. However I seem to be in a similar situation to a few people in that my code passes your test but does not pass the part 2 question, with my answer being too low.
If anyone has a spare minute and wouldnt mind looking at some (imo well organised) Java code, id be very appriciative
This data set helped me locate a bug: I hadn't noticed that J was the weakest card in the tie breaks in part 2. Changing that in my case was just moving the Joker enum value to the top, but this made it fairly easy to find!
Ugh. I am also in the same state as others who pass with the given input as well as your input but fail with the real input. Have you found any other changes to make to you test input that might find more edge cases?
Thanks. I resisted looking at this function that you had posted several times. I finally found that the problem in my code happened for a hand of 26J77 which my checker got wrong.
Thank you for the post! It helped me figure out I wasn't taking into account edge case for JJJJJ and classifying this edge case as high card instead of full house.
Going a little crazy here. I have the right answer for P1 on your input and my own sample input, but I keep getting too high of an answer on the real input. Any ideas? Code below.
card_ord = {str(x): i for i, x in enumerate([2, 3, 4, 5, 6, 7, 8, 9, 'T', 'J', 'Q', 'K', 'A'])}
hand_ord = {x: i for i, x in enumerate(\['HC', 'P', '2P', '3OAK', 'FH', '4OAK', '5OAK'\])}
def compute_hand(h):
ha = Counter(h)
cc = Counter([v for k, v in ha.items()])
if 5 in cc:
return '5OAK'
if 4 in cc:
return '4OAK'
if 3 in cc and 2 in cc:
return 'FH'
if 3 in cc:
return '3OAK'
if cc.get(2, 0) == 2:
return '2P'
if 2 in cc:
return 'P'
else:
return 'HC'
def cmp(h1, h2):
# Get the hand type
h1a = hand_ord[compute_hand(h1)]
h2a = hand_ord[compute_hand(h2)]
# Get high card, if we need to compare HC to HC
h1h = card_ord[sorted(h1, key=lambda x: card_ord[x])[-1]]
h2h = card_ord[sorted(h2, key=lambda x: card_ord[x])[-1]]
if h1a > h2a:
return 1
if h1a < h2a:
return -1
# First check is redundant since we only get this far if they're equal
# Check that they're equal to HC (lowest score)
if h1a == h2a == 0:
if h1h > h2h:
return 1
if h1h < h2h:
return -1
# They're tied and its not a high card situation
for c1, c2 in zip(h1, h2):
if card_ord[c1] > card_ord[c2]:
return 1
if card_ord[c1] < card_ord[c2]:
return -1
# True tie, but i guess there's none?
return 0
import functools
sum([int(x[1]) * (i+1) for i, x in enumerate(sorted(lines, key=lambda x: functools.cmp_to_key(cmp)(x[0])))])
Psst: your spoiler tags are borked because your Markdown isn't correct. You need one space between a closing !< and another opening >! immediately after it, but no spaces between the opening >!, text, and closing !<.
Thanks for posting this. I tested my code for part 1 and got it correct but was still frustrated because AoC was telling me I was wrong. Turns our I copied the data wrong! I really should have double checked that earlier. 😫
This is such an amazing post and I only wish I saw it last night before staying up for hours trying to figure out which edge cases I forgot about.
FYI, I was one of those which got the correct answer for your inputs but the wrong one for the prompt. Idk what I was doing wrong, but I went through and super cleaned up how I was checking for Joker-augmented hands and once I passed your sample input again I passed the AoC input. So I guess there's still an edge case that isn't covered yet? I could have also been doing something drastically wrong before I changed my code.
I've got a Fortran solution for Part 1 that works on all of the example inputs, including getting the correct sort order and the correct sum for this example here too -- but the site says the output for my puzzle input is "too low", still. I've manually combed through the output logs for my real input, and I haven't been able to find anything that it's not handling correctly despite the site's attestation otherwise.
My solution is based around the idea of packing all of the information about the hand into a single integer value that will then sort in the correct order, and from which the bid for each hand can then be extracted.
Thanks for sharing, your examples helped me debug a problem with my part 1. It worked for the original test input but not with the actual puzzle input. Turns out I had a typo and accidentally assigned the same rank to two of the possible strengths, doh!
I had an interesting test input. It provided the same end result if you ordered the hands in wrong order. Ie, ordering hands from strongest to weakest and from weakest to strongest gave the same end result (the sum of (hand's bid * hand's rank)).
To those worrying about using the Js multiple times, theres an easier way:
To determine the card type you can simply add the amount of Js to the highest match of a hand. It always results in the best possible hand. And it works fine since it doesn't matter if the J is matched with an A or B in a hand AABBJ.
Only edge case I ran into was JJJJJ - I actually added a simple equal check for that.
thanks a ton - this helped me find a couple edge cases - my solution still wasn't quite right but once I solved the other issues I was able to find my defect.
I don't understand in part 1 why the three lines are ordered like this:
2JJJJ 53
2AAAA 23
JJJJ2 41
For me, 2JJJJ and JJJJ2 are the same hands. both of them are a four of J and the remaining card is a 2. So the strength should be lower of 2AAAA which is a four of A with a remaining card of 2.
There are a lot of comments so I might have misse done - but if there is a full house then the joker is already being counted as the set of two or set of three and then should be a set of 5 correct?
Example: J5J55 should be a set of 5- not be upgraded to 4? Same with J5J5J?
Shouldn't a single J with no other multi-occurrence of other cards be left alone?
If it's pair then will J be another 'A'? as A is the highest card?
Here are my replacement card hands of your test cases of Input:
Max count: 1 Q2KJJ Replaced by Q2KKK Max count: 2 T3T3J Replaced by T3T3T Max count: 1 2345J Replaced by 23455 Max count: 1 J345A Replaced by A345A Max count: 3 T55J5 Replaced by T5555 Max count: 2 KTJJT Replaced by KTTTT Max count: 3 QQQJA Replaced by QQQQA Max count: 4 JAAAA Replaced by AAAAA Max count: 4 AAAAJ Replaced by AAAAA Max count: 1 2JJJJ Replaced by 22222 Max count: 1 JJJJ2 Replaced by 22222
Are they wrong? Because you list the Output with J in the Ranking, I can't be sure my translation is wrong. I have kept the ranking algorithm as it is as Part1.
for me Part 2 in the test case of AOC is working. It's not giving the right answer for the puzzle input of (1000 hands) and for your test cases too.
Omg, you saved my Christmas! Struggled with this for days!! Painful days debugging and not seeing just 1 simple missed test cenario... Thank you very much for this!
Hi , I know I am late to ask this , but I tried your input and my part1 answer is correct , I checked my code thoroughly everything looks fine to me still its not passing . Is there any chance that the answer is wrong at their end?
Ok My bad , got my silly mistake which was causing some of the cards landing in wrong type. Got passed :) . Thanks anyways , I was quite demotivated and lost all hopes but seeing others comments here gave me some positivity .
•
u/daggerdragon Dec 07 '23
General FYI:
.gitignore15
u/Dazzling_Patient7209 Dec 07 '23
I get the correct answer for part2 but still don't pass....
4
u/cagdassalur Dec 07 '23
For part 2, how is
J345Asorted below2345J? both are high cards, so J should make them both single pairs, and it should come down to card strength.2is weaker thanJ, so shouldn'tJ345Abe better than2345J?3
u/Pakosh Dec 07 '23
Thanks, it helped me. When I was reading part 2 I just added
Jto the end"AKQJT98765432"=>"AKQJT98765432J"without checking thatJwas already here.3
u/Disastrous-Fan4543 Dec 07 '23 edited Dec 07 '23
EDIT: No longer stumped! Forgot to check if the jokers were already used as stand if for other cards before considering them as standalone cards. So the error was discovered when two jokers could both make a three of a kind with another card as well as be a pair by themselves, making full house when it should'nt be.
[Part 2] I am stumped, I get the correct order and output on your test case as well as any i've made myself. And I have quadruple checked that I have the correct input, but still my answer is just wrong.Sorry for the terrible code but essentially for part 2 I did the change in the cards list, and in the getType function, pop 'J' before finding the most common elem, and then add +1 to its count for each 'J', and then add the count of 'J's back before determining the type. (as int 1-7 -> five of a kind - high card respectively)The fix was to simply multiply `jcount` with `not maxCard`, both of them are non-zero only when there both are `J`s in the hand and there is no card they have been used to boost:
3
u/phil_g Dec 07 '23
Just a note on spoiler tags:
Different clients and web interfaces can render spoiler tags differently. The only way to ensure that tags are rendered correctly for everyone is to not have any spaces between the exclamation points and the content. Some of your spoiler tags didn't render correctly for me on Old Reddit because there were spaces between the
>!and the spoiler text.So this will work work everywhere:
These might work in some places, but are not guaranteed to work everywhere:
For reference, here's what each one looks like rendered:
No spaces
Left Space
Right Space
Both Spaces
3
u/Queenshactus Dec 07 '23
Hi. For some reason my code for part 2 works on this extended input but not on my actual input. Does anyone have en more optimized extended input?
2
u/i_have_no_biscuits Dec 07 '23
Always good to see more sample inputs for challenges. Sadly I'm at work all day today but this will definitely be useful this evening when I get to Day 7!
2
u/WillMatt Dec 07 '23
Helpful input tweak that helped me identify a bug in my Four of a Kind/Full House logic. Not all bids are prime but if properly sorted should still be in order .
Total for Part 2: 7460
2345A 1Q2KJJ 13Q2Q2Q 19T3T3J 17T3Q33 112345J 3J345A 232T3K 5T55J5 29KK677 7KTJJT 34QQQJA 31JJJJJ 37JAAAA 43AAAAJ 59AAAAA 612AAAA 232JJJJ 53JKQKK 21JJJJ2 412
u/dmgcodevil Dec 07 '23
my code is passing all test inputs from this thread for part 2 but still giving me the wrong answer for the actual input. sad
2
u/tsanev9611 Dec 14 '23
Why for part 1 this output is like that?
`
2JJJJ 53
2AAAA 23
JJJJ2 41
JAAAA 43`
Since they are four of a kind - J and A (stronger), shouldn't this be like that ?
`2JJJJ 53
JJJJ2 41
2AAAA 23
JAAAA 43`
2
u/CodingNeeL Dec 07 '23 edited Dec 07 '23
Warning: part 2 spoilers ahead!
Nice, I did the same thing for debugging for part 2 and wanted to share my list but then saw your post. I guess I'll drop it here as a comment instead.
I just assume everyone can sort on card strength well enough when you reach part 2, so I only made a list to make sure you'd get the right hand strength:
The bids correspond to the hand strength where
1is high card,2is one pair,3is two pair,4is three of a kind,5is full house,6is four of a kind,7is five of a kind.Note that this is not the order these should be sorted into, because I ignored card strength. I just made a list to get the correct hand strength.
Edit: freaking Reddit Fancy Editor messes up code blocks if you paste in your code
Edit: Emphasised this is only for part 2 and only focuses on hand strength and ignores card strength
Edit: extended the five of a kind list for completion
1
u/jaydoee Dec 15 '23
u/LxsterGames - are you able to provide any insight to me? I used your new input date (big thank you - it helped me catch some issues that were existing in my code) - I have since fixed my code. With your input - it is generating the expected output for part 1: 6592, however, my code is still failing for the actual puzzle input. I've walked through it many times and I'm at a loss for what it could be. My ranking and bids line up with what you have there.
1
u/_justartichoke Mar 16 '24
Thank you ❤
1
u/enelen Dec 07 '23
Thank you for this! This finally helped me realise the problems in my code
1
u/Regcent Dec 07 '23
Thank you so much for this... Reading your output made me realize I made a terrible mistake in reading the instructions... Even if the point about J cards being the weakest is very visible...
1
u/Perfect-Cry-9924 Dec 07 '23
Thanks a lot for that list. My code worked perfectly except it didn't detect 5 jokers as 5 of a kind.
1
u/Piggelinmannen Dec 07 '23
This is great! Was already done, but this would have saved me a lot of headache.
1
u/PityUpvote Dec 07 '23
Thanks a ton. I wasn't handling five-of-a-kinds right and wondering wtf went wrong with my actual input.
I was saving the numbers of each card in a sorted tuple, i.e. full house is
(2,3), but then comparing the tuple(5,)to the integer(5)in my logic and thinking it was a high card by default. Sometimes I hate python.1
u/Aggravating_Line_623 Dec 07 '23
Thank you, thank you, thank you!
I was getting a Part2 wrong result, albeit the AoC example returned the right value. Your test was most helpful in spotting a bug that would have taken me a long time to discover
1
u/T3sT3ro Dec 07 '23
add a
aabbJkind of case which which should result in full house (in my case it produced 3 of a kind)1
u/DjBricheta Dec 07 '23
So I have a small issue.
My part 1 solution works for the original test input, for your test input, but doesn't work for the actual input (the sum is too high) and I have no clue why.
Code: https://pastebin.com/MDkpb0CH
1
u/petit-nuage-org Dec 07 '23
Thanks for sharing !
It seems like the case 234JJ -> THREE_OF_A_KIND is not in your input (according to the coverage of my solution)
1
u/wh4tsuup Dec 07 '23
[Part 1] Why is
JJJJ2higher ranked than2AAAA? The instruction mentionsA>K>Q>J...1
u/[deleted] Dec 07 '23
Thank you!
1
u/Lars-Kristian91 Dec 07 '23
Thank you for input data. It help me find my bugs. :)
1
u/mickayrex Dec 07 '23
The real killer for me was JJJJJ
1
u/GroovyCactiCat Dec 07 '23 edited Dec 07 '23
Thank you, it made me find an error. Unfortunately my answer is still wrong even though I get the correct output from your example. Even with a full house like KKJAA. This is so frustrating :/
Code (sorry I know it's messy):
https://pastebin.com/ye29KVjw
Edit: I hate Python(first time Im trying it out). My issue was literally placing a break one tab indent too little.
1
u/Jekasachan123 Dec 07 '23
Okay,I'm officially confused, my solution matches your output for part2 but when i run it through actual input something is still wrong. Guess it's back to the drawing board.
1
u/thewhiteafrican Dec 07 '23
THANK YOU!
Finally realized that I was sorting my Five Of A Kind hands as Full House instead.
The test input they gave us today was far too simple.
1
u/JonathanSchneider Dec 07 '23
Thank you very much for posting this!
This helped me track down a bug in my Part 1 where I was failing to sort on the 5th card in "high card" hands.
I'm working in Python for the first time this year; lesson learned on how "range" is *exclusive*, not inclusive, on the second argument. That is, to get the set of values {0, 1, 2, 3, 4}, you need to do range(0, 5), not range(0, 4).
1
u/The_Edifice Dec 07 '23
Thank you! I assumed that in a hand with one 'J' no conversion would take place.
1
u/CanalWeaselGames Dec 07 '23
Thank you for this! It helped me debug so much.
1
u/wimglenn Dec 07 '23
Thanks for the extra example. I've added it to my CI and test suite in https://github.com/wimglenn/advent-of-code-wim/pull/89
1
u/Coumbaya Dec 07 '23
what the hell. I have the correct order, and the same sum at the end than fort part 1, and I still don't get your result for part 2. The method to calculate the bids doesn't change right ?
1
u/Rein215 Dec 07 '23
Why is
2JJJJordered so highly in your part 2 output?I have:
1
u/Worth-Medicine-9303 Dec 07 '23
i know you know. but 34 is not prime :)
1
u/wigitty Dec 07 '23
Thanks! This helped a lot.
1
u/cbh66 Dec 07 '23
Thank you so much for this! This helped me pin down the one case I'd missed for part 2 (a single J means you must have at least 1 pair).
1
u/pavel1269 Dec 07 '23
Joining others and big Thanks for this as larger example helped me nail down my errors.
In part 1 i had a wrong detection for two pairs.
In part 2 i calculated jokers twice, Q2KJJ was suddenly four of a kind.
1
u/Leogendra Dec 07 '23
I get the same output for part 1 but it didn't work on my input 💀
1
u/coenvanl Dec 07 '23
I spent a lot of time looking for problems, only to realise that three of a kind of jokers, means you have four or a kind. Perhaps add that case to your sample input as well?
1
u/Fedorai Dec 07 '23
Thanks! I was able to solve it with your inputs!
1
u/Zaphoidx Dec 07 '23
Thanks so much for this.
The examples this year are making it extremely hard to work out the edge-cases that are being missed when putting through the full input.
I realised that I was adding the Joker counts to themselves, which was resulting in me getting lower than expected values. The Q2KJJ test case helped point that out for me
1
u/Silverer48 Dec 07 '23
Thank you so much, this is what I needed to find the bug, ty!<3
1
u/Reidy12124 Dec 07 '23 edited Dec 07 '23
Thank you very much for this, its greatly appricated. However I seem to be in a similar situation to a few people in that my code passes your test but does not pass the part 2 question, with my answer being too low.
If anyone has a spare minute and wouldnt mind looking at some (imo well organised) Java code, id be very appriciative
https://github.com/Reidy12345/AdventOfCode2023Java/tree/main/src/main/java/org/reidy12345/day07
Edit: Link to Day07 rather than the root of the git project
1
u/robertotomas Dec 07 '23
I'm confused about this:
JJJJJ 37
JJJJ2 41
For the hand type sorting, they are both 5 of a kind. for the sort by cards, j > 2, shouldn't their order be reversed?
1
u/14m4 Dec 07 '23
Amazing, thank you! Your example input and score helped me identify a bug in my code for part 2 🎉
1
u/robertotomas Dec 07 '23
awesome post thank you!
This data set helped me locate a bug: I hadn't noticed that J was the weakest card in the tie breaks in part 2. Changing that in my case was just moving the Joker enum value to the top, but this made it fairly easy to find!
1
u/Rusty_retiree_5659 Dec 07 '23
Ugh. I am also in the same state as others who pass with the given input as well as your input but fail with the real input. Have you found any other changes to make to you test input that might find more edge cases?
1
u/mirsella Dec 07 '23
Thank you so much !
1
u/rotellam1 Dec 07 '23
This was very, very helpful, thank you!
1
u/chubchubbutt Dec 07 '23
Thank you for the post! It helped me figure out I wasn't taking into account edge case for
JJJJJand classifying this edge case as high card instead of full house.1
u/corbosman Dec 07 '23
Input worked correctly on my part1/part2. Always good to know.
1
u/Wekmor Dec 07 '23
All your test inputs worked, but I had 3JKQK count as full house on accident. Took me wayyy to long to figure out haha
1
u/kebabmybob Dec 07 '23 edited Dec 07 '23
Going a little crazy here. I have the right answer for P1 on your input and my own sample input, but I keep getting too high of an answer on the real input. Any ideas? Code below.
1
u/daggerdragon Dec 07 '23
Psst: your spoiler tags are borked because your Markdown isn't correct. You need one space between a closing
!<and another opening>!immediately after it, but no spaces between the opening>!, text, and closing!<.Check your post on old.reddit here.
1
u/pecet Dec 07 '23
Thanks for that, I figured out because of this, that I have error and return 4 of kind for 5 of kind in part1. Now for part2...
1
u/nurdyguy Dec 07 '23
Thanks for posting this. I tested my code for part 1 and got it correct but was still frustrated because AoC was telling me I was wrong. Turns our I copied the data wrong! I really should have double checked that earlier. 😫
1
u/elkshadow5 Dec 07 '23
This is such an amazing post and I only wish I saw it last night before staying up for hours trying to figure out which edge cases I forgot about.
FYI, I was one of those which got the correct answer for your inputs but the wrong one for the prompt. Idk what I was doing wrong, but I went through and super cleaned up how I was checking for Joker-augmented hands and once I passed your sample input again I passed the AoC input. So I guess there's still an edge case that isn't covered yet? I could have also been doing something drastically wrong before I changed my code.
1
u/Neither_Wealth4190 Dec 07 '23
Thank you! KTJJT case was where I went wrong with my alg, wasn't properly accounting for multiple jokers and instead made it a full house.
1
u/orizach01 Dec 07 '23
dammit, I kept failing part 1 but finally I noticed I wrote TJKQA instead of TJQKA oof
1
u/Taerina Dec 07 '23
Thank you! Your example helped me find what I was missing.
1
u/AJMansfield_ Dec 07 '23 edited Dec 11 '23
I've got a Fortran solution for Part 1 that works on all of the example inputs, including getting the correct sort order and the correct sum for this example here too -- but the site says the output for my puzzle input is "too low", still. I've manually combed through the output logs for my real input, and I haven't been able to find anything that it's not handling correctly despite the site's attestation otherwise.
Here's a link to the code:https://github.com/AJMansfield/aoc/blob/master/2023-fortran/src/07/camel.f90 You can also clone the entire repo and run it with
make run, assuming you have gnu make and gfortran installed.My solution is based around the idea of packing all of the information about the hand into a single integer value that will then sort in the correct order, and from which the bid for each hand can then be extracted.
1
u/azgx00 Dec 07 '23 edited Dec 07 '23
For part1, why is
Q2Q2Q>QQQJA?Both cards each have 3 cards of the same type. The first character is equal. Then for the second character, Q > 2. What am I missing?
Edit: Nevermind, I completely missed the full house part. My bad
1
u/dantdj1 Dec 07 '23
This helped me out a bunch - just wanted to say thanks!
1
u/mkinkela Dec 07 '23
you sir are a life saver :)
1
u/var_ Dec 07 '23
Thanks for sharing, your examples helped me debug a problem with my part 1. It worked for the original test input but not with the actual puzzle input. Turns out I had a typo and accidentally assigned the same rank to two of the possible strengths, doh!
1
u/d1meji Dec 07 '23
Thanks, your example helped me find my bug!
1
u/7UKECREAT0R Dec 07 '23
Ahaa! The five jokers in a row were the problem for me. Big up for this list of edge cases!!
1
u/kaur_virunurm Dec 07 '23
I had an interesting test input. It provided the same end result if you ordered the hands in wrong order. Ie, ordering hands from strongest to weakest and from weakest to strongest gave the same end result (the sum of (hand's bid * hand's rank)).
Did anyone else notice this?
1
u/Bewelge Dec 08 '23 edited Dec 08 '23
To those worrying about using the Js multiple times, theres an easier way:
To determine the card type you can simply add the amount of Js to the highest match of a hand. It always results in the best possible hand. And it works fine since it doesn't matter if the J is matched with an A or B in a hand AABBJ.
Only edge case I ran into was JJJJJ - I actually added a simple equal check for that.
1
u/ditemirkhan Dec 08 '23
Thank you, The Godfather :)
1
u/QultrosSanhattan Dec 08 '23
My crappy algo passed everything without problems: (spoilers)
1
u/Mr-Adult Dec 08 '23
Thanks for the help. Caught my edge case
1
u/iamagiantnerd Dec 08 '23
Thanks a bunch for this, helped me figure out the edge case I got wrong!
1
u/Professional_Pie5856 Dec 08 '23
thank you so much for the data set.
i had messed up the three and full house logic
1
u/Dizzy_Frostino Dec 08 '23
thanks a ton - this helped me find a couple edge cases - my solution still wasn't quite right but once I solved the other issues I was able to find my defect.
1
u/peterfarrell66 Dec 08 '23
Thanks for posting these tests! It helped me correct my mistake again. You're a life saver.
1
u/mir92fr Dec 08 '23
Thanks a lot for this input.
I don't understand in part 1 why the three lines are ordered like this:
For me,
2JJJJandJJJJ2are the same hands. both of them are a four of J and the remaining card is a 2. So the strength should be lower of2AAAAwhich is a four of A with a remaining card of 2.Can you explain me that order ?
1
u/omril Dec 08 '23
Thank you so much, saved my a$s with this.After sorting the characters I used the regex `/(.)\1(.)\2/` instead of `/(.)\1.?(.)\2/` for two pairs
1
u/xhoneybear_ Dec 08 '23
Thank you so much, it helped a lot <3
1
u/vollmilchpulver Dec 08 '23
Thank you very much. That helped me a lot
1
u/Rhonselak Dec 08 '23
Why are these two in this order in the part 1 output? Isn't a two pair starting with a queen ranked higher than one starting with a ten?
1
u/Sheppio Dec 08 '23
u/LxsterGames, thank you for this. Your 'part 2 input' helped me sort out my issue at a point I was about to give up .
1
u/gwenix_pa Dec 08 '23
Thank you so much for this better input, I found my bug!
1
u/Darkshad666 Dec 08 '23
Thanks for this
made me understand my mistake on part 2 with only joker
1
u/Far-Attempt-9661 Dec 09 '23
There are a lot of comments so I might have misse done - but if there is a full house then the joker is already being counted as the set of two or set of three and then should be a set of 5 correct?
Example: J5J55 should be a set of 5- not be upgraded to 4? Same with J5J5J?
1
u/pack6pack Dec 09 '23
Thanks for this, helped me find the issue, where JJJJJ was being ranked higher than it should've :)
1
u/papa_Fubini Dec 09 '23
Really appreciate the help! I messed up on the cases where I had the J's in majority :)
1
u/stedgyson Dec 09 '23
On the pt 2 input this is the real killer
7JJJ7
Deal with that and you can deal with everything. 3 hours of my life I'll never get back
1
u/[deleted] Dec 10 '23
This was so useful, thank you so much!
1
u/Rumengol Dec 10 '23
Thank you for this input, helped me pinpoint that I didn't handle the case where all cards are different but there is a joker.
1
u/Alwdda Dec 10 '23
For the Part 1 OUTPUT, why is
QQQJAaboveQ2Q2Q?I would think
QQQJAis stronger, since:Q>2.But in this ordering
Q2Q2Qis determined stronger.1
u/DOughDOughBird Dec 10 '23
Thank you so much for this! I spent so long trying to figure out what case I was getting wrong and couldn't find it for the life of me
1
u/Frequent_Cellist_655 Dec 10 '23
I'm totally lost, can't figure out why both test inputs work for me but my answer is still wrong.
Is there any chance someone would try my python code? Or point me in a direction?
JJJ34 = 4 of a kind, 2233J = full house.
Merry christmas, everyone!
1
u/No-Top-1506 Dec 11 '23
for Part 2. Why is the ranking for these 2 like that in your Output?
2345A 1
J345A 2
I thought card "2" is stronger than "J" and it should come on Rank 2.
1
u/DoctorWalnut Dec 14 '23
you're a legend, thank you so much for your creativity
1
u/hbobenicio Dec 17 '23
Omg, you saved my Christmas! Struggled with this for days!! Painful days debugging and not seeing just 1 simple missed test cenario... Thank you very much for this!
1
u/Pornthrowaway78 Dec 19 '23
Thanks, 5 Joker hand was tripping me up. :/
1
u/Beautiful_Cycle2697 Dec 23 '23
Hi , I know I am late to ask this , but I tried your input and my part1 answer is correct , I checked my code thoroughly everything looks fine to me still its not passing . Is there any chance that the answer is wrong at their end?
1
u/Original-Regular-957 Dec 28 '23
Thanks for your help, with your example I can figure out my bug, the bug was missing one transformation!
0
u/[deleted] Dec 07 '23
[deleted] — view deleted comment
0
u/[deleted] Dec 07 '23
[deleted] — view deleted comment