Advent of Code 2024 Day 3: Regex

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ธ.ค. 2024

ความคิดเห็น • 15

  • @fegorek
    @fegorek 7 ชั่วโมงที่ผ่านมา +3

    waiting for day 4!

  • @zhangtai
    @zhangtai วันที่ผ่านมา +7

    🐐fastest uploads in the west

  • @benjamineskildsen9649
    @benjamineskildsen9649 วันที่ผ่านมา +8

    The amount of mistakes you can make and still solve in like 2 minutes... what the heck am *I* doing?? Nice job!

  • @God-i2
    @God-i2 วันที่ผ่านมา +10

    🫸Competitive Programming
    👉Competitive thumbnail making and video uploading

  • @sauravmahay9838
    @sauravmahay9838 2 ชั่วโมงที่ผ่านมา

    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

  • @n0ne0ne
    @n0ne0ne 28 นาทีที่ผ่านมา

    no day 4?

  • @harisimer
    @harisimer วันที่ผ่านมา +2

    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  วันที่ผ่านมา +2

      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.

  • @ketanmaurya5294
    @ketanmaurya5294 วันที่ผ่านมา +3

    Would it be possible to show your aoc_tools, Thank you.

    • @nthistlethwaite
      @nthistlethwaite  20 ชั่วโมงที่ผ่านมา

      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.

  • @warrenhenning8064
    @warrenhenning8064 วันที่ผ่านมา +1

    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 23 ชั่วโมงที่ผ่านมา

      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 13 ชั่วโมงที่ผ่านมา

      I did it without regex as well. Not THAT hard

  • @Beesman88
    @Beesman88 19 ชั่วโมงที่ผ่านมา +2

    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 17 ชั่วโมงที่ผ่านมา +2

      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?