Unable to load image
Reported by:

rDrama Advent of Code Day 1: Warm up

I hope this fine morning finds you well, saars.

The word of the day is collections.Counter

The rdrama leaderboard invite code is 632268-30587026

I created the ping group: !AOC, I'm sure it will be useful offseason too.

Charts! https://github.com/jeroenheijmans/advent-of-code-charts

19
Jump in the discussion.

No email address required.

I'll have to try the file reading lambdas some people were using,

ah, and I had forgotten about abs()

I always wonder how much faster some of the cleaner code is, it's all doing the same stuff under the hood usually.

with open("1/input.txt") as f:
    content = f.readlines()
l1 = []
l2 = []

for i in content:
    _ = i.split("   ")
    l1.append(int(_[0]))
    l2.append(int(_[1]))

l1.sort()
l2.sort()

distance = 0
for i in range(len(l1)):
    dist = l1[i] - l2[i]
    if dist < 0:
        dist = -dist
    distance += dist
print(distance)

p2

with open("1/input.txt") as f:
    content = f.readlines()
l1 = []
l2 = []

for i in content:
    _ = i.split("   ")
    l1.append(int(_[0]))
    l2.append(int(_[1]))

l1.sort()
l2.sort()

simularity = 0
for i in l1:
    num = l2.count(i)
    simularity += num * i
print(simularity)
Jump in the discussion.

No email address required.

Depends. Some features like comprehension have some optimization under the hood, but you will mainly see better memory usage than any noticeable performance gains.

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.