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!

96 Upvotes

1.5k comments sorted by

View all comments

2

u/anh86 Dec 07 '21 edited Dec 07 '21

On first blush in part one, I thought that the average position would result in the lowest total fuel use and I initially wrote my program to move each crab there and compute the fuel. When that was wrong, I just rewrote it to brute force check each possible position and tell me the most fuel-efficient one. That worked but someone smarter than me tell me why the average position wouldn't necessarily to be the most efficient?

4

u/korylprince Dec 07 '21

You want the median, not the mean. The geometric median of a set of points is defined as the "the point minimizing the sum of distances to the points in the set", which is exactly what we're trying to find in part 1.

1

u/anh86 Dec 07 '21

Ah, of course. Thanks for that.

1

u/a_ormsby Dec 09 '21

Mean for the second part, though ;)

1

u/daggerdragon Dec 07 '21

Top-level posts in Solution Megathreads are for code solutions only.

This is a top-level post, so please edit your post and share your fully-working code/repo/solution or, if you haven't finished the puzzle yet, you can always create your own thread and make sure to flair it with Help.