Wednesday, December 26, 2018

Advent of Code 2015 - Day 14: Reindeer Olympics

Part 1

Description

Solution

Here is my attempt to solve this problem.

I split the input into four columns: name, speed, bursting time, and resting time. For counting the distance these reindeer covered in the 2503th seconds, I use this formula:

H3: =IF(MOD($E$2,D3+C3)>C3,(1+ROUNDDOWN($E$2/(C3+D3),0))*B3*C3,ROUNDDOWN($E$2/(C3+D3),0)*B3*C3+MOD($E$2,D3+C3)*B3)

The code determine whether those reindeer are resting or bursting. If the time (2503) mod the time needed for the reindeer to burst again (bursting time + resting time) is greater than burst time, then the reindeer is resting. Then the code calculate the distance covered. and simply get the largest value of those distances.

Part 2

Description

Solution

For the part 2, I have to calculate the distance each reindeer covered in every second up to the 2503th and determine which one is leading. Now in column G, I put an array formula to counts how many those reindeer are in the lead, and therefore the point they get. And finally find the largest of those numbers. Here is my array formula:

G3: =SUM(IF(H3:CRN3=H$13:CRN$13,1,0))

Share:

0 komentar:

Recent Posts

Categories

Blog Archive