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

18
Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17330893348163915.webp

Jump in the discussion.

No email address required.

@ogsambone heard you like lambdas

with open('input.txt', 'r') as file:
    f = file.read()

print(sum(abs(a - b) for a, b in zip(*map(lambda x: sorted(map(int, x)), zip(*(x.split() for x in f.strip().split('\n')))))))

print((lambda a, b: sum(y*b.count(y) for y in a))(*list(map(lambda x: list(map(int, x)), zip(*(x.split() for x in f.strip().split('\n')))))))
Jump in the discussion.

No email address required.

Lmao, I was wondering when someone would do some crazy one-liners with zip and map. :pepehacker:

Jump in the discussion.

No email address required.

It took me way longer than it should've to do this one. I feel so incompetent..

Jump in the discussion.

No email address required.

i am anticipating that this years word problems arent going to be as brain frickingly awful as last years

https://i.rdrama.net/images/17330363793963332.webp

Jump in the discussion.

No email address required.

It's called abs() :marseyemojirofl:

Jump in the discussion.

No email address required.

thanks im drunk

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/1733064506532285.webp

Jump in the discussion.

No email address required.

i WILL NOT use LAMBDAS, YOU CAN"T MAKE ME

Jump in the discussion.

No email address required.

:marseyconfused: they didn't use lambdas?

Jump in the discussion.

No email address required.

Ope, im confusing things

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.

>Anonymous user 2335322 with a Part 2 time of 7 seconds

MODS MODS MODS

Jump in the discussion.

No email address required.

first

https://i.rdrama.net/images/17330361832342741.webp

Jump in the discussion.

No email address required.

I'll try this, I created one with my twitter and not my github, opsec is gay :marseycry:

Jump in the discussion.

No email address required.

Not joining because I'm already participating in a leaderboard from work, but will keep an eye on things. Will try to do this year's questions in Zig, or at least until my patience runs out from having to handle every low-level tidbit possible.

Jump in the discussion.

No email address required.

you can join more than one private leaderboard :marseybeanwink:

Jump in the discussion.

No email address required.

#AOC 1. des 1
column1 =[]
column2 =[]

theData = open("Datasets/ids1.12")
theData = theData.readlines()

for line in theData:
  parts = line.split()
  column1.append(int(parts[0]))
  column2.append(int(parts[1]))

column1.sort()
column2.sort()

distance = 0

for i in range(len(column1)):
  distance += abs(column1[i] - column2[i])
print(distance)

Every time I have to use loops I feel like shit, because that is where you get performance bottlenecks. But then I realized I don't have to submit any actual code and just did what came most natural. I am not comfortable with Python and have to relearn shit every time I use it.

#AOC 1. des 2
column1 =[]
column2 =[]

theData = open("Datasets/ids1.12")
theData = theData.readlines()

for line in theData:
  parts = line.split()
  column1.append(int(parts[0]))
  column2.append(int(parts[1]))

column2Dict = {}

for i in column2:
  column2Dict.update({i: 0})

for i in column2:
  column2Dict[i] = column2Dict[i] + 1

simScore = 0

for i in column1:
  if i not in column2Dict:
    continue
  simScore += (i * column2Dict[i])

print(simScore)

The scoring on this seems a little sleep-phobic, not gonna lie. This solution is a little ungabunga, I think I could have avoided one loop if I knew how to python better.


:#marseydisintegrate: :!#marseyflamewar::space::!marseyagree:

Jump in the discussion.

No email address required.

If you really care,

distance = 0
for i in range(len(column1)):
  distance += abs(column1[i] - column2[i])

could be

distance = sum(abs(column1[i] - column2[i]) for i in range(len(column1)))

or

distance = sum(abs(x - y) for x, y in zip(column1, column2))

but in principle they're all for loops. Whatever obscure performance benefits one syntax might offer isn't worth worrying about. Readability is king in python.

Jump in the discussion.

No email address required.

Every time I have to use loops I feel like shit, because that is where you get performance bottlenecks. But then I realized I don't have to submit any actual code and just did what came most natural. I am not comfortable with Python and have to relearn shit every time I use it.

Read other people's code and learn from it. Python is a remarkably nice language, pretty much every time you feel like shit for writing verbose code, that's a red flag telling you that there's a way to write it five times shorter and more to the point.

Jump in the discussion.

No email address required.

dict has get and setdefault methods that deal with nonexistent keys in a streamlined fashion. So column2Dict[i] = column2Dict.get(i, 0) + 1 would work. Even better, use collections.Counter which does all that for you, see my code in a comment here.

Jump in the discussion.

No email address required.

I am not comfortable with Python and have to relearn shit every time I use it.

Then dont do it :marseyconfused:

Jump in the discussion.

No email address required.

I'm like this but for every language I use. I assumed this was just part of the Process?

Jump in the discussion.

No email address required.

Oh ok I thought you had some hangup on python specifically

Jump in the discussion.

No email address required.

I'm not the person in the picture.

Jump in the discussion.

No email address required.

std::ifstream in("1.txt", std::ios::in);
std::string str;
std::multiset<int> l_set, r_set;

while (std::getline(in, str)) {
    l_set.insert(std::stoi(str.substr(0, 5)));
    r_set.insert(std::stoi(str.substr(8, 5)));
}
auto r_it = r_set.begin();
auto l_it = l_set.begin();
int sum = 0, sim = 0;
while (l_it != l_set.end()) {
    sim += r_set.count(*l_it) * (*l_it);
    sum += std::abs(*l_it++ - *r_it++);  
 
}

Wheres the APLChad from last year?

Jump in the discussion.

No email address required.

A B←(⊂∘⍋⌷⊢)¨↓⍉↑⍎¨⊃⎕NGET'input.txt'1
⎕←+/∊|A-B
⎕←+/∊A∘(⊣×=)¨B

The actual APLchads are laughing at me for using ¨ instead of understanding matrix ranks :marseyitsover:

Jump in the discussion.

No email address required.

left_list = []
right_list = []

for line in input_text.split("\n"):
    left_list.append(int(line.split()[0]))
    right_list.append(int(line.split()[1]))
    
left_list.sort()
right_list.sort()

ans = 0
for l, r in zip(left_list, right_list, strict=True):
    ans += l * right_list.count(l)
    
print(ans)
Jump in the discussion.

No email address required.

Solution:

    lst1, lst2 = [], []
    for s in data:
        a, b = s.split()
        lst1.append(int(a))
        lst2.append(int(b))
    lst1.sort()
    lst2.sort()
    if not second:
        return sum(abs(a - b) for a, b in zip(lst1, lst2))
    lst2 = Counter(lst2)
    return sum(x * lst2[x] for x in lst1)
Jump in the discussion.

No email address required.

how long did u take Spider :marseything2:

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17330344433960865.webp

@Platy why do we have two of you o_O

Jump in the discussion.

No email address required.

moved from reddit to a shell github account

Jump in the discussion.

No email address required.

ur so smart :marseyidiotsavant: hearts

Jump in the discussion.

No email address required.

wtf it started one hour earlier than I thought. Now I'm going to be super tired with nothing to gain :marseycrying:

Jump in the discussion.

No email address required.

https://media.tenor.com/lwhopqox5EMAAAAx/luigis-mansion-sleep.webp

Me reading 16 morbillion parapgraphs on how to sum a number milliseconds after waking up

Jump in the discussion.

No email address required.

Yeah they're def cheating starting an hour early. This whole thing is officially fraudulent

Christmas is ruined.

Jump in the discussion.

No email address required.

@X (formerly known as twitter) join the ping group. Also idk, is it better to post these into the main feed or /h/slackernews?

Jump in the discussion.

No email address required.

slackernews probably. Anyone who has blocked it wouldn't join anyways.

Jump in the discussion.

No email address required.

I love how in a span of 2 days the new site has already buck broken a bunch of jannies. :#marseyfeminist:

Jump in the discussion.

No email address required.

I don't get it :marseysad:

Jump in the discussion.

No email address required.

Jannies have always played hard ball with this website.

Jump in the discussion.

No email address required.

What do you mean? :marseyconfused:

Jump in the discussion.

No email address required.

They always go and make these new rules that they expect everyone to follow without even asking or trying to get consensus.

Now they've made a new site. :marseyparty:

Jump in the discussion.

No email address required.

But you are a janny? :marseyconfused:

Jump in the discussion.

No email address required.

I'm a good janny, I listen to the people! :marseytunaktunak:

Jump in the discussion.

No email address required.

I joined the leaderboard just to spy on your GitHub accounts :marseytroublemaker: i think it doesn't matter, where were last year's post posted?

Jump in the discussion.

No email address required.

I kinda deleted last year's leaderboard to make place for a new one :platythumbsup:

If people use the same accounts then you can still see the results from 2023 though

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

yeah thats the one I created, I notice that theres only 3 new people so far on this years...

Jump in the discussion.

No email address required.

where were last year's post posted?

https://rdrama.net/search/posts?q="advent+of+code"

In the hole, so I'll continue from now on.

Jump in the discussion.

No email address required.

@LetsUnpackThis heyooo space cowboy!

Jump in the discussion.

No email address required.

not gonna lie when I saw that ping group created I thought it was about the politician

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17330309776932876.webp

Jump in the discussion.

No email address required.

Just subtract everything from the left column and add everything in the right column? Is there even a need too pair them?

It took @AnnoyinTheGoyim longer too read the bullshit story than figure out the solution.

@AnnoyinTheGoyim love sucking peepee.

Jump in the discussion.

No email address required.

You gotta sort them. Also use absolute values of differences.

Jump in the discussion.

No email address required.

Didn't read most of it. Kind of stupid too say the distance can't be negative. Is the hard part just reading all the bullshit? If they cut out the stupid story, I'd actually read the entire problem.

@AnnoyinTheGoyim love sucking peepee.

Jump in the discussion.

No email address required.

Yes, understanding the problem is the hard part usually.

Jump in the discussion.

No email address required.

They should just explain the problem and not surround it in 10 paragraphs of story then. @AnnoyinTheGoyim is trying too drink, not read a novel.

@AnnoyinTheGoyim love sucking peepee.

Jump in the discussion.

No email address required.

irl work simulator

Jump in the discussion.

No email address required.

I was first inline at a shop counter and two indigenous people behind me. The shop assistant looked at us and asked "ok who is first". I said, "they are of course, they have been here for more than 60,000 years". The two idigenous people smiled and thanked me as I stood aside.

Snapshots:

collections.Counter:

Jump in the discussion.

No email address required.

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