sorry about the poor audio quality; i changed my setup today and a different device took my audio and i didn't notice. i'll have this fixed in the next video but i don't really have time to re-record this one today. thanks! :3
I really hope you complete the series this year. I'm doing it as a hobbyist. Today took me awhile because I knew I needed to use a regex but without GPT support it was actually pretty hard to figure out what I needed to write "for the regex". It'd be great to compare daily with people really proficient who explain what they're doing. Now to try to do it in golang.
i plan to complete it, yes! and fair enough - you might've noticed from the start of each video that i have copilot but i don't want to use it for AoC and i usually just use it for boilerplate at work. figuring out the regex took me a bit too, TBH
@@hyper-neutrino What is the AoC ruling on copilot / AI? I'm also not using it because I do this mostly to learn to problem-solve. I know last year it was very much forbidden, but I know copilot has become more common-practice since then in industry.
@@hyper-neutrino idm the copilot support... at this point we gotta get used to it cause it's likely here to stay. Personally I take the ghost text but still type everything manually just to get the fingers working if that makes sense. Really do appreciate it. I need to go thru your day 04 ceres search. Your final grid solution is elegant.
Alternative solution for part 2: Replace everything between an don't() and a do() in your 'memory' with an empty string (so basically remove it) and then use the solution of part one on the remaining memory. The regex to do the replacement would be: r"don't\(\).*?do\(\)"
I didn't read the part about X and Y only containing a max of three digits and just matched the regex to \d+ and it worked. Don't know if I got lucky with my input or that case wasn't tested in any of them.
i think this just wasn't tested for. i also forgot this, but unfortunately i also didn't look at my input (i have a script to load it) and missed that it's not a single line which is what did me in today
Is there a reason to not do \d+? I'm not sure why we're specifying {1-3}, unless it was in the rules that we should exclude numbers under 1000. Also I didn't use r string and it seems to work the same - "mul\(\d+,\d+\)"
sorry about the poor audio quality; i changed my setup today and a different device took my audio and i didn't notice. i'll have this fixed in the next video but i don't really have time to re-record this one today. thanks! :3
the part2 regex is so clean! You can also use a capturing group for the numbers in the pattern. The numbers still need to be casted to ints tho.
very good point, that probably would've been a much more elegant solution
I'm not familiar with regex so I used classic str matching with indices instead - slower and less compact. Something to practice for the next few days
Could have used capture groups in the findall to get tuples of just the numbers.
true, i usually don't use capture groups unless i need to but i should get more familiar with them
yup this is the strat
Came here to comment the same. Capture groups is just free parsing in this case
I really hope you complete the series this year. I'm doing it as a hobbyist. Today took me awhile because I knew I needed to use a regex but without GPT support it was actually pretty hard to figure out what I needed to write "for the regex". It'd be great to compare daily with people really proficient who explain what they're doing.
Now to try to do it in golang.
i plan to complete it, yes! and fair enough - you might've noticed from the start of each video that i have copilot but i don't want to use it for AoC and i usually just use it for boilerplate at work. figuring out the regex took me a bit too, TBH
also learning golang could be neat but it's not high on my list - if i'm going to learn a new language it's going to be rust
@@hyper-neutrino What is the AoC ruling on copilot / AI? I'm also not using it because I do this mostly to learn to problem-solve. I know last year it was very much forbidden, but I know copilot has become more common-practice since then in industry.
@@hyper-neutrino idm the copilot support... at this point we gotta get used to it cause it's likely here to stay. Personally I take the ghost text but still type everything manually just to get the fingers working if that makes sense.
Really do appreciate it. I need to go thru your day 04 ceres search. Your final grid solution is elegant.
Gesundheit!
Alternative solution for part 2:
Replace everything between an don't() and a do() in your 'memory' with an empty string (so basically remove it) and then use the solution of part one on the remaining memory. The regex to do the replacement would be: r"don't\(\).*?do\(\)"
interesting idea, i like it! wouldn't it need to be r"don't\(\).*?(do\(\))?" or do we not need to catch that case?
I didn't read the part about X and Y only containing a max of three digits and just matched the regex to \d+ and it worked. Don't know if I got lucky with my input or that case wasn't tested in any of them.
same here
i think this just wasn't tested for. i also forgot this, but unfortunately i also didn't look at my input (i have a script to load it) and missed that it's not a single line which is what did me in today
Same here 😅
same!
Is there a reason to not do \d+? I'm not sure why we're specifying {1-3}, unless it was in the rules that we should exclude numbers under 1000. Also I didn't use r string and it seems to work the same - "mul\(\d+,\d+\)"
The problem statement specifies 1-3 digit numbers, but \d+ works because the dataset doesn’t have numbers with 4+ digits anyway
I create almost 1:1 solutuon 😂 but more functional style, maybe you can try FP in Python?
Here's my more or less pythonic solution:
(spoiler!)
# pt1
OPER_RE = re.compile(r"mul\((\d{1,3}),(\d{1,3})\)")
def mul_match_to_value(m: re.Match) -> int:
return math.prod(map(int, m.groups()))
print(sum(map(mul_match_to_value, OPER_RE.finditer(DATA))))
# pt2
DO_DONT_RE = re.compile(r"do(n't)?\(\)")
all_matches_sorted = sorted(
itertools.chain(
OPER_RE.finditer(DATA),
DO_DONT_RE.finditer(DATA),
),
key=lambda m: m.span()[0],
)
enabled = True
res = 0
for m in all_matches_sorted:
matched_string = DATA[slice(*m.span())]
if matched_string.startswith('mul'):
res += enabled * mul_match_to_value(m)
else:
enabled = matched_string == 'do()'
print(res)