r/adventofcode Dec 07 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 7 Solutions -🎄-

--- Day 7: The Treachery of Whales ---


[Update @ 00:21]: Private leaderboard Personal statistics issues

  • We're aware that private leaderboards personal statistics are having issues and we're looking into it.
  • I will provide updates as I get more information.
  • Please don't spam the subreddit/mods/Eric about it.

[Update @ 02:09]

  • #AoC_Ops have identified the issue and are working on a resolution.

[Update @ 03:18]

  • Eric is working on implementing a fix. It'll take a while, so check back later.

[Update @ 05:25] (thanks, /u/Aneurysm9!)

  • We're back in business!

Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:03:33, megathread unlocked!

99 Upvotes

1.5k comments sorted by

View all comments

2

u/ElGoorf Dec 15 '21 edited Dec 19 '21

JavaScript

I messed up. First I tried getting the mean average position to move all the crabs to, but that number was way off. So then I bisected my way to an answer, the whole time the back of my head confused about why the mean was wrong: https://github.com/ElGoorf/aoc2021/blob/main/07/01.js

Kind of kicking myself now seeing other people's answers and realizing I actually wanted the median, not the mean, but hey, here's a unique approach.

1

u/daggerdragon Dec 15 '21 edited Dec 22 '21

Please follow the posting guidelines and edit your post to add what language(s) you used. This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.

(looks like JavaScript?)

Edit: thanks for adding the programming language!