Advent of Code 2024 Day 3: Regex

  Рет қаралды 5,852

Neil Thistlethwaite

Neil Thistlethwaite

Күн бұрын

Пікірлер: 24
@benjamineskildsen9649
@benjamineskildsen9649 Ай бұрын
The amount of mistakes you can make and still solve in like 2 minutes... what the heck am *I* doing?? Nice job!
@zhangtai
@zhangtai Ай бұрын
🐐fastest uploads in the west
@fegorek
@fegorek Ай бұрын
waiting for day 4!
@zhangtai
@zhangtai Ай бұрын
neil im sorry for putting pressure on your uploads. every day i pray for your glorious return. take care.
@nthistlethwaite
@nthistlethwaite Ай бұрын
haha no worries, I just did pretty badly on day 4 (and day 5...) so I got a little demoralized and didn't feel like uploading - but it would be a little cheesy if I didn't show the bad days, so day 4 is up now! day 5 should be out pretty soon too
@God-i2
@God-i2 Ай бұрын
🫸Competitive Programming 👉Competitive thumbnail making and video uploading
@ketz7
@ketz7 Ай бұрын
Would it be possible to show your aoc_tools, Thank you.
@nthistlethwaite
@nthistlethwaite Ай бұрын
Here's a gist with the file: gist.github.com/nthistle/5244b04be6a2eae545e6908369d39592 Mostly I just use nums function, although I've occasionally used adj4 and adj8 as well. I've shadowed print because in a newer version of IDLE (which I used on my laptop last year while I was in Korea) you can't interrupt print statements, so if you accidentally put a print in a tight loop then it would kinda just freeze. The other functions like adjacent_pairs, all_pairs, all_tuples, and rolling_sum are probably useful, but I'll usually just re-write a simplified version on the fly if i want them rather than call these functions.
@harisimer
@harisimer Ай бұрын
Part 1 you should capture the factors, that way it can be done in one line in most languages. I think thats how they got it so fast. for example c# this gives you the result: new Regex(@"mul\((\d+),(\d+)\)").Matches(input).Sum(m => int.Parse(m.Groups(1).Value) * int.Parse(m.Groups(2).Value))
@nthistlethwaite
@nthistlethwaite Ай бұрын
Yeah, that makes sense - mostly I just didn't remember the exact syntax for getting the capture groups from a match object in Python (and I always forget whether the first capture group is the entire match or not), and I already had my `nums` function, so I just went with what I knew. I definitely could have been faster here.
@QuotePilgrim
@QuotePilgrim Ай бұрын
I couldn't use regex* because I'm doing it in Lua so I just wrote the stupidest looking matching pattern you can possibly imagine. (* I mean technically I could if I used an external library)
@n0ne0ne
@n0ne0ne Ай бұрын
no day 4?
@nthistlethwaite
@nthistlethwaite Ай бұрын
it's up now!
@jfb-
@jfb- Ай бұрын
i got 99 problems so i used a regex and now i have 100 problems
@sauravmahay9838
@sauravmahay9838 Ай бұрын
Your gonna think im stupid, but i did a slidin window thing, where the window should match a hardcoded byte array, icl this made pt2 mad quick tho... W speed tho gaadamn
@warrenhenning8064
@warrenhenning8064 Ай бұрын
this problem is kind of a pain in the ass if you do it in a language that doesn't have regexes in the standard library :( good job!
@no_name4796
@no_name4796 Ай бұрын
Or you can not use regex and do it manually... I did it that way in golang, and it's around 30 lines of code...
@gerardomiranda2284
@gerardomiranda2284 Ай бұрын
I did it without regex as well. Not THAT hard
@QuotePilgrim
@QuotePilgrim Ай бұрын
Not really. I did it in Lua and it was fine.
@jfb-
@jfb- Ай бұрын
@@QuotePilgrim lua has a pattern match system that is similar enough to regex that it works for this
@QuotePilgrim
@QuotePilgrim Ай бұрын
@@jfb- Yes, I am aware. What do you think I've used in my solution? It is *not* "similar enough to regex", though. Sure, some approaches to the problem would be very similar using either regular expressions or Lua string matching but if you want a single pattern that matches all of "mul(123,456)", "do()" and "don't()" without also matching some things that don't quite fit the pattern, you can't really do that with Lua string matching, in regex it's just "mul\((\d+),(\d+)\)|do\(\)|don't\(\)".
@Beesman88
@Beesman88 Ай бұрын
I really disliked \d+ worked (from what i saw so far in everyones input) I never write regex right first time without googling or testing, so i had to find the {lower,upper} count syntax since my brain didn't remember it, yet it would reward me for not reading the constraint of 1-3 digits since \d+ my brain does remember..
@FirSouL3
@FirSouL3 Ай бұрын
Yep, they should have added at least a test case with a number higher than 999, otherwise why even mention that it should have 3 digits at most?
@nthistlethwaite
@nthistlethwaite Ай бұрын
Ah yeah I didn't even notice the 1-3 digits constraint until well after I had solved. I probably would have been in a similar boat as you if I did see it, since I also didn't remember how to do a range for number of characters to match.
Destroying everyone else in Advent of Code 2021 Day 22
19:08
Neal Wu
Рет қаралды 268 М.
Advent of Code 2024 Day 4
31:46
Neil Thistlethwaite
Рет қаралды 2,9 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Advent of Code 2024 Day 12 - 16th Gold Star!
22:33
Neil Thistlethwaite
Рет қаралды 3,8 М.
How to get the most out ADVENT OF CODE
7:33
Andrew Burgess
Рет қаралды 15 М.
Advent of Code Day 24
57:20
Egor Kulikov
Рет қаралды 118
Why YOU Should Do Advent of Code
4:34
Theo - t3․gg
Рет қаралды 37 М.
Day 5 | Advent of Code 2024
20:56
Errichto Algorithms
Рет қаралды 6 М.
Advent of Code 2024 Day 24 - 12th place!
51:54
Neil Thistlethwaite
Рет қаралды 2,9 М.
Day 2 | Advent of Code 2024 | Better Time Complexity
15:14
Errichto Algorithms
Рет қаралды 12 М.
i dove down the 7z rabbit hole (it goes deep)
12:50
Low Level
Рет қаралды 633 М.
Day 3 - Advent of Code 2024 (Solution)
39:00
James Peralta
Рет қаралды 306
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 945 М.