Unable to load image

rDrama Advent of Code Day 7: 25% Edition

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

38
Jump in the discussion.

No email address required.

I just started doing this after 7 days of ignoring it, so despite having 10 stars already I only have 140 points, RIP

Edit: finished all 7 puzzles so far, still only 243 points :(

Jump in the discussion.

No email address required.

It's hard to move up the board. Think about it this way: if the guy directly above you has 10 more points than you, then to overtake him, you and 9 other people need to finish the next problem faster than that guy. A tall order.

You could also try to do the problems late at night. Only half of the top 20 is probably doing that right now. Personally, I do this shit first thing in the morning. Frick programming at 11:00 PM or whatever, I don't have anywhere near that kind of energy.

Jump in the discussion.

No email address required.

lul i just work on it on my phone when im waiting for other stuff

i already know im not sweaty enough to compete but the puzzles are kinda fun

Jump in the discussion.

No email address required.

I have had no time to do it day by day and won't even have an opportunity to catch up by next week. It's nice that you can go and do previous years whenever.

Jump in the discussion.

No email address required.

I do more of these than I ever have of any real leetcode website, I like the fun stories and weird constraints it's like a contrived uni assignment

Jump in the discussion.

No email address required.

Scoring is wack, more answers should always mean a higher ranking

Jump in the discussion.

No email address required.

Part 2s are generally harder and so should deliver more points. Later days should also get extra points due to difficulty. Someone solving only Day 24 should rank higher than someone only solving Day 1.

Jump in the discussion.

No email address required.

Maybe one useful metric to give points to latecomers is to assign points for completing a puzzle that many people accessed but fewer solved. If you completed day X, and only 10% of people who started day X did so, that should be worth more than completing a day that 90% of people solved.

Jump in the discussion.

No email address required.

Tbh the "first solved = most points" system is rather unfair when it's a global leaderbord. Given the limited options built into AoC I'd suggest "most stars" ranking to be the fairest available.

Jump in the discussion.

No email address required.

True, but much like today's problem, you'd need a second-order ranking for all the people with the same number of stars, which is going to have to be time solved anyway.

Jump in the discussion.

No email address required.

hmm, maybe teaching people that noncodecels think like this

Jump in the discussion.

No email address required.

This was actually a relatively simple problem, unfortunately I wasted a ton of time on Part 2 by not reading the question properly ("There's no 5 of a kind in poker!")

Jump in the discussion.

No email address required.

I did something similar on part 1 by inverting the score of two hands, it's frustrating.

Jump in the discussion.

No email address required.

I thought the second ordering would be normal poker rules not just which card in the list is bigger. :marseyfacepalm:

Jump in the discussion.

No email address required.

Had part 2 really fast at 99% but missed the edge case where my "most frequent" function would return the joker sometimes and then the joker wouldn't get assigned to the actual most frequent letter :marseyrope:

Using linqs "List.Distinct()" operator gets you 90% of the way there as long as you can design a switch case for the result with the right precedence tbh

  • 1 distinct value is always 5 of a kind

  • 2 distinct is 4 of a kind if the first character has 1 or 4 occurances, otherwise it's a full house

Etc etc

If you have a joker you just decrement the distinct count and add all the jokers to the next most common card

Then cover the edge cases

Create a hand class and overload the compareto operator and then sort each type of hand using it.

(Don't have my code please enjoy my textual description)

Jump in the discussion.

No email address required.

I feel like there is a clever way to do this and I over-engineered but it works https://i.rdrama.net/images/17019334060865524.webp

Jump in the discussion.

No email address required.

I will never forgive eric wastl for making me wait FIVE minutes to submit another answer

I'm a sovereign federal citizen programmer, you are unlawfully impeding my constitutional right to fix one bug, rerun my program, and see if it works now

Jump in the discussion.

No email address required.

>it tells you if you're high or low

anyone write a script to binary search it yet?

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17019662130297713.webp

Trans lives matter

Jump in the discussion.

No email address required.

Unwashed:

https://i.rdrama.net/images/17019582232199886.webp

Jump in the discussion.

No email address required.

wish i knew what i was looking at, looks neat

Jump in the discussion.

No email address required.

There's an extremely neat solution some APL gigachad will come up with, but that gigachad is not me.

o←(,5)(4 1)(3 2)(3 1 1)(2 2 1)(2 1 1 1)(1 1 1 1 1)
p1←'AKQJT98765432' ⋄ p2←'AKQT98765432J'
r←⊃⎕NGET'7.in'1 ⋄ bi←⍎¨6↓¨r ⋄ ci←5↑¨r ⋄ so←⊂∘⍋⌷⊢ ⋄ sr←⊂∘⍒⌷⊢

c←ci⌷⍨⊂⍋t←o⍳sr¨{≢⍵}⌸¨ci ⋄ u←c⊆⍨so t
⎕←+/(⍳∘≢×⊢)bi⌷⍨⊂ci⍳⌽⊃,/u{⍺⌷⍨⊂⍵}¨⍋¨p1∘⍳¨¨u

mcc←{2⊃1⌷sr{(≢⍵),⍺}⌸((⊂∘⍋p1∘⍳)⌷⊢)'J'~⍨⍵}
cj←{(,'J')≡∪⍵:5\'A' ⋄ (mcc ⍵)@(=∘'J')⊢⍵}¨ci
c←ci⌷⍨⊂⍋t←o⍳sr¨{≢⍵}⌸¨cj ⋄ u←c⊆⍨so t
⎕←+/(⍳∘≢×⊢)bi⌷⍨⊂ci⍳⌽⊃,/u{⍺⌷⍨⊂⍵}¨⍋¨p2∘⍳¨¨u

Brehs I think I have the neat solution but there's this dumb event I have to go to. Sitting on the train and all I can think about is APL encodings. Gonna be a long evening.

Jump in the discussion.

No email address required.

I don't know how you can internalise these magic runes and go on to ever think about anything other than APL encodings

Jump in the discussion.

No email address required.

I coded a solution and it's not working. Not going to debug it :marseyautismdisconcerting:

Jump in the discussion.

No email address required.

I've fallen off the wagon, go on without me bros, I'll catch up Saturday

Jump in the discussion.

No email address required.

10 INPUT "WHAT IS YOUR NAME"; NAME$

20 PRINT "THAT IS A BIPOC NAME"

30 BEEP

40 GOTO 20

Jump in the discussion.

No email address required.

I love BASIC. I have an old NEC PC and sometimes I get bored and write little functions

Jump in the discussion.

No email address required.

It's all I ever learned, and barely anything

Jump in the discussion.

No email address required.

My code sucks lol https://i.rdrama.net/images/17019648638823757.webp

Jump in the discussion.

No email address required.

Part 1:

https://i.rdrama.net/images/1701959865682186.webp

Part 2:

https://i.rdrama.net/images/17019598666575847.webp

Didn't like this one much.

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/1701966983161101.webp

CountTable is very handy here. toCountTable turns a list of items into a CountTable that maps each item to its amount. If you try to access a key that doesn't exist, it returns 0 rather than throwing.

Jump in the discussion.

No email address required.

meh cba part 2 just looks like array busywork + it would go offscreen

https://i.rdrama.net/images/17019955391304815.webp

Jump in the discussion.

No email address required.

Phone Hypertext Processor is some kind of vibe

Jump in the discussion.

No email address required.

it really is

perfect to pass the time if there's something I'm waiting on and I just dont feel like consuming random internet shit

Jump in the discussion.

No email address required.

This was quite chill, I sorta plodded through it but I'm happy with the easy retrofit

https://i.rdrama.net/images/1701948001629169.webp

Jump in the discussion.

No email address required.

Whoops can't believe I missed this, c as usize - 48 also works but that feels less cool in a non-C language

https://i.rdrama.net/images/17019481987584336.webp

Jump in the discussion.

No email address required.

:mars#eyglow2:

Rust sure does take away some avenues of “cleverness”

Jump in the discussion.

No email address required.

If you really really push you can do bit-level trickery but you can feel the compiler sooking on the way through

Jump in the discussion.

No email address required.

It was actually an easy puzzle, but I missed the part about the second ordering rule and thought it was normal Poker ordering. Wasted a lot of time with that shit

https://i.rdrama.net/images/17019955718803973.webp

Jump in the discussion.

No email address required.

My solution for both parts

https://i.rdrama.net/images/17019657240844154.webp

Edit: Just realized that I can generate absolute hand values rather than doing everything comparatively.

https://i.rdrama.net/images/17019721439617481.webp

Jump in the discussion.

No email address required.

God python is so ugly

Trans lives matter

Jump in the discussion.

No email address required.

My code was so terrible that I'm not gonna bother posting it this time lol (100+ lines)

I thought it was standard poker rules and only once I had a fully working solution did I realize I didn't properly read the problem and had to messily stitch it into what it was actually supposed to be doing

Jump in the discussion.

No email address required.

This was a fun one

f = open('AOC2023Day7.txt')
lines = f.read().strip().split('\n')
lines = [line.split() for line in lines]
from collections import defaultdict
def sanitize(hand):
   r = [i for i in hand]
   for i in range(len(r)):
       if r[i] == 'T':
           r[i] = 10
       elif r[i] == 'J':
           #r[i] = 11
           r[i] = 1
       elif r[i] == 'Q':
           r[i] = 12
       elif r[i] == 'K':
           r[i] = 13
       elif r[i] == 'A':
           r[i] = 14
       else:
           r[i] = int(r[i])
   return r
def count(hand):
   rdict = defaultdict(lambda: 0)
   for i in hand:
       rdict[i] += 1
   return rdict
def compareh(hand1,hand2):
   hand1 = sanitize(hand1)
   hand2 = sanitize(hand2)
   ch1 = count(hand1)
   ch1copy = ch1.copy()
   ch1copy[1] = 0
   ch2 = count(hand2)
   ch2copy = ch2.copy()
   ch2copy[1] = 0
   ch1v = sorted(ch1copy.values(),reverse=True)
   ch2v = sorted(ch2copy.values(),reverse=True)
   ch1v[0] += ch1[1]
   ch2v[0] += ch2[1]
   if ch1v > ch2v:
       return 1
   if ch2v > ch1v:
       return -1
   if hand1 > hand2:
       return 1
   if hand2 > hand1:
       return -1
   return 0
def compare(l1,l2):
   return compareh(l1[0],l2[0])
from functools import cmp_to_key
slines = sorted(lines,key= cmp_to_key(compare))
vals = [(i+1)*int(slines[i][1]) for i in range(len(slines))]
print(sum(vals))
Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.