Advent of Code 2024 Day 3

Поделиться
HTML-код
  • Опубликовано: 10 дек 2024

Комментарии • 24

  • @Jm4cc4
    @Jm4cc4 8 дней назад +4

    Your solution to have an enabled state variable for part two was a nice elegant solution - I really liked it! my solution there was clunky and required a list of index position for the ends of do's and don'ts so I can then find what the most recent do or don't was.

  • @firehandszarb
    @firehandszarb 13 часов назад +1

    yes today I had to cheat and look at your code. Your's is the best example I''ve found. Some solutions are overly complex yet they type it out on the screen like there is no problem. I managed to get the first part done myself (in julia using regex) but the second part was nearly impossible. I'm still not sure why I couldn't get mine to work, my regexes looked fine. maybe I just needed to strip out the newlines, having now cheated I'm going to try to figure out what I needed to do in my own version. So thanks for sharing this video it probably helped my mental and physical health.

  • @ozoniuss1463
    @ozoniuss1463 7 дней назад +3

    To shave off a few more seconds before the regex, instead of
    if D[j-1] not in ['1', '2', '3', '4', '5', '6', '7', '8', '9']
    writing
    if D[j-1] not in '123456789' (to be thorough, list('123456789') but it's a singe char so it works here)
    should have done the same. Might have helped win a few places.
    I always watch your solution right after I finish mine, learned a lot of python "shortcuts" from it. And it's fun to watch someone compete. Good luck with the leaderboard!

  • @paulthebault9546
    @paulthebault9546 8 дней назад +3

    Hi, rough day when regexes aren't your strong suit
    I saw you miss the p2 answer when double clicking/copying, maybe you could have something that automatically copies the last printed thing? Either by aliasing print or with some shell config. Seeing how close the leaderboard is on those first days, it could earn you some points
    Have fun this year!

  • @ninadsachania3652
    @ninadsachania3652 8 дней назад

    Glad I wasn't the only one who had trouble with regular expressions. :^)

  • @Bhuyakasha
    @Bhuyakasha 2 дня назад

    I had the opposite problem, too much regex. Used regex to modify the input for part two and removed between the first don't() and do(), however there were some newlines sneaked into the input which messed it up. That was so annoying to debug.

    • @not_my_name5200
      @not_my_name5200 2 дня назад +1

      thanks! this actually helped me find the bug...

  • @RiesenpiIz
    @RiesenpiIz 8 дней назад +1

    you can do Ctrl+z and fg to switch between vim and the terminal faster

  • @sergioeduardo3797
    @sergioeduardo3797 7 дней назад +1

    Why doesn't the solution require an increment to i after matching the mul expression?

    • @jonathanpaulson5053
      @jonathanpaulson5053  7 дней назад +1

      The for loop is incrementing i. I’m checking for a match in all possible starting positions.

    • @sergioeduardo3797
      @sergioeduardo3797 7 дней назад

      @jonathanpaulson5053 I understand that, I'm wondering why it doesn't pick the same match multiple times. If you have fjdjdjdjmul(123,132) isn't the match function picking up the mul? It only matches when you reach with i?

    • @sergioeduardo3797
      @sergioeduardo3797 7 дней назад

      Never mind, it's the re.search function that would match my example and return a Match object.

  • @alessiodvt
    @alessiodvt 8 дней назад

    You can press ctrl+z to suspend vim and type fg to come back

  • @avalagum7957
    @avalagum7957 8 дней назад +1

    Wow, you used a regular vim (i.e. no language support from the editor) to write python, that means you knows python very very very well.

    • @FatjonFreskina
      @FatjonFreskina 7 дней назад

      Dude also knows vim itself pretty well 😂

  • @arnehuffmeier3386
    @arnehuffmeier3386 8 дней назад +1

    Hi, there is another error in your regex.
    The ‘+’ can stand for any number of numbers. But the task says that it should only be 1-3 numbers. Your regex would be ‘mul(1234,1234)’ accept, but that would not be correct.
    For Part 1 you can also use only regex.
    part1 = 0
    x = re.findall(r ‘mul\(\d{1,3},\d{1,3}\)’, data)
    for i in x:
    a, b = i[4:-1].split(‘,’) # cut mul( and the )
    part1 += int(a)*int(b)
    There are very good regex builders on the Internet that help you to create the appropriate excerpt.

    • @pashi47
      @pashi47 8 дней назад

      He changed it to \d{1,3} later if you didn't watch that far

    • @arnehuffmeier3386
      @arnehuffmeier3386 8 дней назад

      @@pashi47 oh sorry. Yes, he changes it in minute 12. I wish I'd watched it to the end.

    • @yante7
      @yante7 8 дней назад +1

      i used "+" and got the right answer for both parts. i don't think it matters

    • @ungerfall
      @ungerfall 8 дней назад +1

      Hmm. It seems my input didn’t have long digits and \d+ worked