Advent of Code 2024 Day 1

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 41

  • @nkeylen
    @nkeylen 26 днів тому +12

    My favourite video serie of December is back... Thanks and good luck!

  • @BLRMalcolm
    @BLRMalcolm 26 днів тому +6

    Amazing watching you resolve this puzzles at this speed, as always. Im happy because my solution was identical as yours. It's only the first of dec, but It means a lot for me since it means I've evolved a lot. In the right way.

  • @Sandborg_
    @Sandborg_ 26 днів тому +12

    Another december, another AoC. Gl with the leaderboard this year, Jonathan!

  • @umairgillani699
    @umairgillani699 26 днів тому +2

    I got motivation from you and started coding in VIM with bash. Now I can code like you, but can't actually think like you. Hopefully day I'll be thinking as fast as you as well.

  • @gupta_samarth
    @gupta_samarth 26 днів тому +7

    Good night! Damn it's late for you, you have real pressure to solve the harder ones quickly

  • @CB27255
    @CB27255 26 днів тому +2

    The king is back. 🎉🎉 look forward to coding along with you this year.

  • @deraileddash
    @deraileddash 26 днів тому +2

    Nice to see you again this December!

  • @ParthPatel-om4on
    @ParthPatel-om4on 24 дні тому +2

    How do you read and understand the questions so fast? Do you have tips on practicing this skill?

    • @jonathanpaulson5053
      @jonathanpaulson5053  17 днів тому +2

      The key thing is to only read the important stuff. If you boil it down, you only need to read a few sentences to understand every advent of code problem.
      For this one, the key sentences in part 1 are "pair up the numbers and measure how far apart they are. Pair up the smallest number in the left list with the smallest number in the right list, then the second-smallest left number with the second-smallest right number, and so on.
      Within each pair, figure out how far apart the two numbers are; you'll need to add up all of those distances."
      This completely describes the problem; you don't need to read anything else to understand what's going on.
      For part 2, the key sentence is: "Calculate a total similarity score by adding up each number in the left list after multiplying it by the number of times that number appears in the right list." You don't need to read anything else.
      Reading these key sentences doesn't take long, but it might be tricky to figure out what they are.
      You always want to skip past the story. You probably want to glance at the example input just to see what the data format is like. Sometimes there is useful information around there. The bottom also often has useful information because it has a one-sentence summary of the problem (e.g. for part 1 this is "What is the total distance between your lists?" which actually isn't that useful because its not clear what "total distance" means).

    • @ParthPatel-om4on
      @ParthPatel-om4on 16 днів тому

      @@jonathanpaulson5053 thanks for the tips, got t500 on pt 2 day 11 by skimming more efficiently

  • @koosman
    @koosman 26 днів тому +3

    Two small changes you could make:
    LEFT = sorted(LEFT) could simply be LEFT.sort()
    There's no need to manually add items to a counter; you could rather use RC = Counter(RIGHT) -- which also makes RC a defaultdict, so then you can use RC[l] to your heart's content.

  • @KunalSrivastava-p6h
    @KunalSrivastava-p6h 10 днів тому

    What's the final answer?

  • @jordanlitko
    @jordanlitko 25 днів тому +1

    Total noob question here, but could you point me in the right direction for learning how to navigate the cursor through the code so efficiently like you do here? It's super impressive.

    • @jonathanpaulson5053
      @jonathanpaulson5053  25 днів тому +2

      Running “vimtutor” from your shell will walk you through like a half hour lesson.

    • @jordanlitko
      @jordanlitko 25 днів тому

      @@jonathanpaulson5053 thanks so much!

  • @amole7344
    @amole7344 26 днів тому +4

    Your new keyboard is too quiet, I miss the sound of your typing from previous years :-).
    Congrats on good start. Btw, Counter by default returns 0 for missing entries so RC[l] would also give the correct result.

    • @jonathanpaulson5053
      @jonathanpaulson5053  26 днів тому

      thanks. that's what I thought but then I got confused by the error (that was actually about reusing the same variable name for the list from part 1...)

  • @rastislavsvoboda4363
    @rastislavsvoboda4363 20 днів тому

    lines_puzzle = open('1.in').readlines()
    data = [line.split() for line in lines_puzzle]
    # part1
    Xs = sorted([int(x) for x,_ in data])
    Ys = sorted([int(y) for _,y in data])
    print(sum([abs(x-y) for x,y in zip(Xs,Ys)]))
    # part2
    xs = set(Xs)
    print(sum(filter(lambda y: y in xs, Ys)))

  • @NeoTheone-r7k
    @NeoTheone-r7k 26 днів тому

    Why exactly do you import defaultdict? What's its purpose?

    • @jonathanpaulson5053
      @jonathanpaulson5053  26 днів тому +1

      I meant to import Counter but I typed the wrong thing

    • @NeoTheone-r7k
      @NeoTheone-r7k 26 днів тому

      @jonathanpaulson5053 thanks :) I read your code but only skipped through the Video (maybe watching it would have answered that question already. So ty! )

  • @MyCipherComplete
    @MyCipherComplete 25 днів тому +1

    It took me ~30 minutes using Python! I'm going for completion this year, all 25. I only got 12 last year before reaching my limit.

    • @jonathanpaulson5053
      @jonathanpaulson5053  25 днів тому

      You got this! Did you go back and finish last year later?

    • @MyCipherComplete
      @MyCipherComplete 24 дні тому

      @@jonathanpaulson5053 Thanks! nope didn't finish. Do you recommend doing so? I only code as a hobby, so it takes a lot of effort xd

    • @jonathanpaulson5053
      @jonathanpaulson5053  24 дні тому +1

      @@MyCipherComplete If it's fun for you, going back through the archives and solving everything after-the-fact is a great way to get better. It can be tough to keep up with everything during December but all the old problems are available forever.

    • @MyCipherComplete
      @MyCipherComplete 24 дні тому

      @@jonathanpaulson5053 definitely. I will do it for this years problems for sure!

  • @mihirbpi
    @mihirbpi 26 днів тому

    28 degrees F. where do you live?

  • @sdemji
    @sdemji 26 днів тому

    what program are you using to run linux on windows ?

  • @marttielvisto3519
    @marttielvisto3519 26 днів тому +1

    RR = Counter() from collections import defaultdict haha

    • @maxheadroom5532
      @maxheadroom5532 26 днів тому

      He's #29 on the leaderboard with a baby crying in the background, so I think that can be excused ;)

    • @marttielvisto3519
      @marttielvisto3519 25 днів тому

      @@maxheadroom5532 Obviously. It's just a bit funny

    • @maxheadroom5532
      @maxheadroom5532 25 днів тому

      @@marttielvisto3519 yeah, but the idea of him muting his mic for a second while coding to go 'shhhhh, I'll be there in a minute!' is also kinda funny :P

  • @mailoisback
    @mailoisback 25 днів тому +1

    You are slow. I did it in 9 seconds!

    • @jonathanpaulson5053
      @jonathanpaulson5053  25 днів тому

      All hail our new robot overlords :) I feel like en.m.wikipedia.org/wiki/John_Henry_(folklore) trying to keep up with the machine.

  • @every116
    @every116 26 днів тому +4

    Lol I can only compete on the weekends and still got about 2500th place. Good job getting on the leaderboard.
    I didn't think to use Counter for part 2, I just used List.count(arg) multiplied by the value. It's probably faster to execute doing it your way but it still runs instantly for me.

    • @weirddan455
      @weirddan455 26 днів тому +2

      Your way is quadratic time while using the Counter (or a HashMap keeping track of frequencies in other languages) is linear time. So your way is quite a lot slower but with only 1000 elements in the input, it'll still be fast enough.

    • @pashi47
      @pashi47 26 днів тому +2

      Yeah for AOC runtime never matters unless the problem itself is optimization, usually pathfinding or something similar

    • @alfredomoreira6761
      @alfredomoreira6761 26 днів тому

      @@weirddan455 yep, in my testing in rust, it's 17ms (quadratic) vs 1.6ms (HashMap) so for 1000 elements around 10 times slower