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
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))
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.
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.
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..
waiting for day 4!
🐐fastest uploads in the west
The amount of mistakes you can make and still solve in like 2 minutes... what the heck am *I* doing?? Nice job!
🫸Competitive Programming
👉Competitive thumbnail making and video uploading
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
no day 4?
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))
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.
Would it be possible to show your aoc_tools, Thank you.
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.
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!
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...
I did it without regex as well. Not THAT hard
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..
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?