rDrama Advent of Code Day 6 Discussion Thread

Not sure where @RedNose is so I'll just post this. Post ur solutions below or whatever idc

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)

50
Jump in the discussion.

No email address required.

Did you guys do it the dumb way or the smart way

Jump in the discussion.

No email address required.

Dumb way is a lot faster to write than solving the equation. I still haven't yet placed first out of the dramafriends doing the challenge, and my competitive ambition must be sated

Jump in the discussion.

No email address required.

You need to read N chars, so obviously is O(N).

Jump in the discussion.

No email address required.

:#marseysigh:

Jump in the discussion.

No email address required.

i didnt even finish yesterday. i give up. i cant give a frick anymore because LLMs have ruined fun and this is not fun this year because the entire point of this year is fricking LLMs,which means making the problem texts as obtuse and r-slurred as possible. i havent even read todays problem and im not going to because yesterdays was so egregiously stupid for a day 4 problem. suck my frick, eric.

Jump in the discussion.

No email address required.

just regexmaxx

(i say this without having done yesterday's monstrosity)

Jump in the discussion.

No email address required.

Hitting this year without having done prior problems would be a massive brick wall, I can pattern match to what it's asking but you have to know what's up to do that

E: he's coping about not writing to LLMs but idk if I believe him https://old.reddit.com/r/adventofcode/comments/18bp8id/comment/kc646i4?context=8

Jump in the discussion.

No email address required.

its a fun little problem solving exercise. if u are trying to be competitive that's meh, for me its just a test of my own skill.

some people on here are writing about it like the point is to get a tech job. i mean if that's what u gotta do, fine, but any half-decent tech company is going to know that being fast at solving programming problems doesn't make you a good software engineer, in fact, it might make you a terrible engineer. the code I write for AOC is purposefully terrible because I'm just having fun with it and don't expect anyone else to ever need to modify it or deploy it

anyways don't take any of this too seriously, if it appeals to you do it, if it doesn't appeal to you don't do it. ez

Jump in the discussion.

No email address required.

Good decision of me to not take part this year :marseywholesome:

Jump in the discussion.

No email address required.

The input parsing is really bloating my code. Much easier than yesterday and part2 runs fast enough(2s) that I am wont bother doing fancy math. https://i.rdrama.net/images/17018556751085.webp

Jump in the discussion.

No email address required.

jfc why do people use C++? input parsing in JS is really ez:

const [_, ...times] = lines[0].split(/\s+/g).map(x => +x)

repeat for the distances and you are done.

Jump in the discussion.

No email address required.

Agreed that it's a shit language but it could be written more tersely.

For parsing you could do this:

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

And that's not even using the more modern features of cpp 20.

The full solution ends up not that far off from other compiled languages:

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

Jump in the discussion.

No email address required.

I stored each win and how long you'd to hold down the button separately before, thinking that might become useful in part 2, it didn't. If I remove this and instead just count how often you win (and actually enable release mode), i am down to 29ms.

Jump in the discussion.

No email address required.

There's also the analytic solution, where t is the race time and d is the race distance.

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

Jump in the discussion.

No email address required.

Huge pain in the butt that some roots are ints so you can't just round. Guessing this is where they expected to trip people up.

Jump in the discussion.

No email address required.

yeah I did this first and considered not even writing the code for it lol

I shouldn't have waited until I got home to start I could have done this on a notepad

Jump in the discussion.

No email address required.

If you didn't feel like remembering how to do math, you could also recognize that the winning numbers are always a parabola with the highest point in the center, then just divide the time by 2 and test backwards until it isn't big enough anymore, then multiply the result by 2.

Jump in the discussion.

No email address required.

I mean just brute forcing it took less than a second on my shitty laptop.

Jump in the discussion.

No email address required.

Cancel your negatives, please

Jump in the discussion.

No email address required.

Pretty easy puzzle today.

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

Jump in the discussion.

No email address required.

Oh you guys did it like that? I solved the inequality like an r-slur.

Jump in the discussion.

No email address required.

I was going to do it but the brute force finished quick enough

Jump in the discussion.

No email address required.

I saw the big numbers and didn't even try bruteforcing, meanwhile sweating over solving shit I haven't looked at in 15 years :marseycry:

Jump in the discussion.

No email address required.

wish i knew what u r-slurs are talking about

i cant do shit outside of a for loop and if/else

Jump in the discussion.

No email address required.

This shit:

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

Jump in the discussion.

No email address required.

Did you not do quadratics at school? "negative b plus minus square root of b squared minus 4 a c all over 2 a" is seared into my brain for life.

Not that it mattered, you'd spend minutes writing efficient code for a ~2 second perf boost.

Jump in the discussion.

No email address required.

hmm is it even a performance boost tho? I thought computers suck at division. Or u mean like the xtra computation to derive the answer is less than trying to stick with +-*

Jump in the discussion.

No email address required.

They do, but one equation gives you the solution so it's basically instant. Also the division is by -2 which could just be a bit shift. I think even a binary search brute force would be slower (I cba to check).

Jump in the discussion.

No email address required.

hmm here's what im getting seconds:nanoseconds

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

idk what thead op's language is tho but id be curious to compare

e: absolute dogshit for the 2nd part lmfao 16 seconds

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

Jump in the discussion.

No email address required.

More comments

I did but I forgot nearly everything I learned because I don't use it :\

On one hand it's a quick study session away from being usable info, but then also a few days of not using it away from forgetting it again.

And I do remember that specifically the forumla itself is seared in there but outside of solving for possibilities for x³ + 2x² + 8x or whatever Idk any practical use

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

If they wanted people to solve it the clever way using quadratics roots they should've made brute forcing less appealing

Jump in the discussion.

No email address required.

The 'clever' way is still much easier than most other days https://i.rdrama.net/images/17018419667310154.webp

Jump in the discussion.

No email address required.

What genius put the range-splitting question on day 5 and this on day 6?

s←⍎¨r←11∘↓¨⊃⎕NGET'6.in'1
⎕←×/+/¨(2⊃s)<(⊢×⌽)¨⍳¨-∘1⊃s
t d←⍎¨~∘' '¨r ⋄ ⎕←t-1-⍨2×1∘+⍣{d<⍺×t-⍺}⊢1

Or if you wanna be a nerd and use quadratics:

q←{⌈1E¯10+¯2÷⍨(¯1×⍵)+(*∘0.5)(¯4×⍺)+⍵*2}
⎕←×/1+(⊃s)-2×(2∘⊃q¨⊃)s
⎕←t-1-⍨2×d q t
Jump in the discussion.

No email address required.

What did you think about today's problem?

Are we supposed to be voting based on the difficulty or the quality/fun of the problem?

Jump in the discussion.

No email address required.

I thought it was difficulty and I've been rating them all 1/5 to look smart.

Jump in the discussion.

No email address required.

Advent of code is so r-slurred

Just sexy Indian dudes doing generic tasks so they can brag on LinkedIn.

Yea bro google will notice yu spent your xmas indoors doing pointless code

Jump in the discussion.

No email address required.

Let people enjoy things! :soycry:

Jump in the discussion.

No email address required.

It takes like 20 minutes and is a fast way to explore a new language, plus you get to have fun and share it with other people, see solutions you wouldn't have thought off, learn idiomatic expressions, ...

It has better examples than most official docs.

Jump in the discussion.

No email address required.

Thanks babe I got stuck in a meeting

Jump in the discussion.

No email address required.

I'm sure a search is a worst-of-both-worlds middle ground, but it's fun to regurgitate from memory

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

Jump in the discussion.

No email address required.

this one was so much easier

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

Jump in the discussion.

No email address required.

https://media.giphy.com/media/nlbn2yC76XIha/giphy.webp

Jump in the discussion.

No email address required.

@transb-word stop exiling people pls bb

Jump in the discussion.

No email address required.

twas a joke before christmas

Jump in the discussion.

No email address required.

ok then

Jump in the discussion.

No email address required.

part 1 is here

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

for part 2 I just plugged the coefficients into wolframalpha I'm not coding the quadratic equation lol (and didn't want to spend time thinking about rounding errors)

Jump in the discussion.

No email address required.

This did seem like an unusual puzzle for advent of code with the tiny input files. You don't really need to program much to solve it. They usually make the input so long that there's no way you're going to do it by hand.

Jump in the discussion.

No email address required.

I like this

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

Jump in the discussion.

No email address required.

ikr! bing ai image gen

Jump in the discussion.

No email address required.

lol, lmao

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

Jump in the discussion.

No email address required.

Solve each race in O(1) using highschool math

the distance you can travel is given by d = p(T-p), where T is the total amount of time, and p is how long you hold the button. (This is just d = v*t, but the time you have is also dependent on the velocity)

This forms a parabola with zeros at p = 0 (so you never press the button) and p = T (you never let go). Naturally the optimum is at T/2.

next find the p that corresponds the record distance. So do r = p(T-p), where r is the record distance. You'll use the quadratic formula and get two big equations which I won't type out here.

finally ge the distance between both values of p using subtraction. if you do this the terms cancel out and you are left with sqrt(T^2-4r). This is (pretty much) the value you are looking for

(You'll need to do some small adjustments but they are uninteresting)

Jump in the discussion.

No email address required.

:marseyxd: This was just basic math+avoiding integer overflow

f = open('AOC2023Day6.txt')
import numpy as np
from collections import defaultdict
def dist(hold,time):
    return hold*(time-hold)
def zero(time,dist):
    time = float(time)
    dist = float(dist)
    return (time+ np.sqrt(np.power(time,2)-4*dist))/2,(time-np.sqrt(np.power(time,2)-4*dist))/2
lines = f.read().strip().split('\n')
times = [int(i) for i in lines[0].split()[1:]]
dists = [int(i) for i in lines[1].split()[1:]]
wins = [0 for i in times]
for i in range(len(times)):
    time = times[i]
    distance = dists[i]
    for t in range(time):
        if dist(t,time) > distance:
            wins[i] += 1
zeros = zero(42686985,284100511221341)
print(np.floor(zeros[0])-np.ceil(zeros[1])+1)
print(np.product(np.array(wins)))
Jump in the discussion.

No email address required.

>Integer overflow error

>Ctrl+f '32', Replace with '64'

>Ctrl+f 'int', Replace with 'long'

>Run again

Jump in the discussion.

No email address required.

That Marsey looks kinda Downsy.

Jump in the discussion.

No email address required.

Pretty straightforward, nice break from yesterday.

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

Jump in the discussion.

No email address required.

Got this for n°1, n°2 done by hand:

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

Wish I had known about prod lol, couldn't find it in the docs because I was searching "mul".

Jump in the discussion.

No email address required.

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

I was hoping for a twist with how easy part 1 was (I noticed several patterns with the output) but nope

Jump in the discussion.

No email address required.

:#marseysanta:

Jump in the discussion.

No email address required.

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