Day 3 | Advent of Code 2024

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

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

  • @siddharth-gandhi
    @siddharth-gandhi День назад +12

    wow that adding hashes at end is a great idea!

  • @gauravshah7888
    @gauravshah7888 День назад +3

    Thanks for the video! Also :
    Everyone, please add this case in your test case if possible : ...mul(mul(45,67)... and ...mul(63,mul(12,56)....
    In both this cases, we should consider 45*67 and 12*56.

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd День назад +14

    How are you doing Errichtho, Where had you been, long time no see, no videos, how is life going?

  • @Woofer21
    @Woofer21 День назад +2

    Love being able to see other peoples thought processes with these puzzles, personally I used a regex to solve it which ended up being a fairly clean solution.

  • @anuraglamsal5142
    @anuraglamsal5142 День назад

    Loving these!

  • @0x00-V
    @0x00-V 17 часов назад

    I'm learning C++. For this problem i used regular expressions

  • @MemeConnoisseur
    @MemeConnoisseur 22 часа назад +1

    regex pattern matching could maybe do it in 10 lines. i am not writing that lol

  • @hussein-alemam
    @hussein-alemam Час назад

    I get it in exactly 10 lines in python using regexes
    I bet some crazy ppl get it in even less lines

  • @mrlectus
    @mrlectus День назад

    Even I was thinking part 2 was going to be nested mul 😅

  • @praveenpp2929
    @praveenpp2929 22 часа назад

    why not use regex ? but its really very nice to do it with out regex though nice to see this .

  • @barterjke
    @barterjke 19 часов назад

    I understand that regex is not everyone's cup of tea, but why not to use the full power of c++ ?
    std::cin >> s or getline(std::cin, s)? reallocate string is really inefficient. and you could have used strtol for parsing number
    I like how you added hashes to avoid checking for boundaries. It was clever :)

  • @codingmickey
    @codingmickey День назад

    Long time no see

  • @archeryo5218
    @archeryo5218 4 часа назад

    Where's day 4!!!!

  • @legenddxd
    @legenddxd День назад

    First

  • @animesh_chouhan
    @animesh_chouhan День назад +6

    We can actually solve both parts in one line in Python using regex:
    Part 1:
    print(sum(int(x) * int(y) for x, y in re.findall(r"mul\((\d+),(\d+)\)", open('input.txt').read())))
    Part2: A bit complicated due to flag.
    print(sum(int(x) * int(y) for match in re.findall(r"mul\(\d+,\d+\)|do\(\)|don't\(\)", open("input.txt").read()) if (flag := (match == "do()") or (match != "don't()" and globals().get("flag", True))) and match.startswith("mul(") for x, y in [match[4:-1].split(",")]))
    # One-liner un-rolled:
    print(
    sum(
    int(x) * int(y)
    for match in re.findall(
    r"mul\(\d+,\d+\)|do\(\)|don't\(\)", open("input.txt").read()
    )
    if (
    flag := (match == "do()")
    or (match != "don't()" and globals().get("flag", True))
    )
    and match.startswith("mul(")
    for x, y in [match[4:-1].split(",")]
    )
    )

    • @everluck35
      @everluck35 День назад +10

      just no.

    • @Vastaway
      @Vastaway День назад

      i am never going to understand how to use regex lol

    • @alh-xj6gt
      @alh-xj6gt День назад +4

      Thank you as I don't code in python, great to see! I got very lazy and joined all lines of input within vim :%s/
      //g and stripped the "not to evaluated" part with :s/don't().\{-}do()\|don't().\{-}$//g
      That way part 1 solution doesn't need to be touched. the vim regex translated to reg ex website equivalent for explanation: /don't\(\).*?do\(\)|don.t\(\).*?$/g

    • @MrAdhit
      @MrAdhit 23 часа назад

      just... don't use regex for parsing pls

    • @cubernetes
      @cubernetes 11 часов назад

      @@MrAdhit regex is literally meant for parsing lol, as long as your input is a type 3 language in the chomsky hierarchy