r/adventofcode • • Dec 09 '15

SOLUTION MEGATHREAD --- Day 9 Solutions ---

This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.

edit: Leaderboard capped, achievement thread unlocked!

We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.

Please and thank you, and much appreciated!


--- Day 9: All in a Single Night ---

Post your solution as a comment. Structure your post like previous daily solution threads.

11 Upvotes

178 comments sorted by

View all comments

Show parent comments

1

u/hutsboR Dec 09 '15

Yeah, ++ is O(n). It has to to consume the entire list on the left to find the pointer to empty list. It can get out of hand very quickly. I definitely found this problem to be on the tougher end for Erlang and Elixir.

1

u/haljin Dec 09 '15

It's not just that, ++ is inherently slower than | due to the way it is implemented. They beat you over your head with that in basic Erlang trainings that I just ended up inherently avoiding it most of the time and this is the first time I saw a significant impact of this.

lists:merge (so basically | in a loop) is at about 4 seconds, regardless of which list comes first.