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.
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.
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).
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.
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.
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.
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...)
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)))
@jonathanpaulson5053 thanks :) I read your code but only skipped through the Video (maybe watching it would have answered that question already. So ty! )
@@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.
@@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
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.
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.
My favourite video serie of December is back... Thanks and good luck!
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.
Another december, another AoC. Gl with the leaderboard this year, Jonathan!
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.
Good night! Damn it's late for you, you have real pressure to solve the harder ones quickly
Yup. Hopefully won't be too many late nights...
The king is back. 🎉🎉 look forward to coding along with you this year.
Nice to see you again this December!
How do you read and understand the questions so fast? Do you have tips on practicing this skill?
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).
@@jonathanpaulson5053 thanks for the tips, got t500 on pt 2 day 11 by skimming more efficiently
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.
What's the final answer?
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.
Running “vimtutor” from your shell will walk you through like a half hour lesson.
@@jonathanpaulson5053 thanks so much!
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.
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...)
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)))
Why exactly do you import defaultdict? What's its purpose?
I meant to import Counter but I typed the wrong thing
@jonathanpaulson5053 thanks :) I read your code but only skipped through the Video (maybe watching it would have answered that question already. So ty! )
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.
You got this! Did you go back and finish last year later?
@@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
@@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.
@@jonathanpaulson5053 definitely. I will do it for this years problems for sure!
28 degrees F. where do you live?
NYC
what program are you using to run linux on windows ?
WSL2. It’s great!
RR = Counter() from collections import defaultdict haha
He's #29 on the leaderboard with a baby crying in the background, so I think that can be excused ;)
@@maxheadroom5532 Obviously. It's just a bit funny
@@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
You are slow. I did it in 9 seconds!
All hail our new robot overlords :) I feel like en.m.wikipedia.org/wiki/John_Henry_(folklore) trying to keep up with the machine.
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.
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.
Yeah for AOC runtime never matters unless the problem itself is optimization, usually pathfinding or something similar
@@weirddan455 yep, in my testing in rust, it's 17ms (quadratic) vs 1.6ms (HashMap) so for 1000 elements around 10 times slower