hackathon/question/q05/q05.md

2.7 KiB

The time has arrived and you need to pack things up and say goodbye. You are leaving for the Farlands, and it's.. far!

You plan to fly solo over the continents to make it to the Farlands. This is the first time you've ever flown for so long, and so you need to prepare a few things before leaving.

The first order of business is to determine how much fuel you're going to need to reach. To do this, you need the empty mass of your aircraft.

With the mass, you can calculate the total required fuel.

For each each mass, the amount of fuel can be calculated using this formula. Take the mass, divide it by 2.5, round down the result, and then subtract 2.

Before taking off, your friends and family have sent you hundreds of gifts, which you plan to take with you. You'll need to know the total amount of fuel needed for your trip.

Apply the formula for each item (your input), and sum them to get the total requirement.

Example

For a mass of 18, divide it by 2.5 and round down to get 7, then subtract 2 to get 5 as the fuel requirement.

For a mass of 58, divide it by 2.5 and round down to get 23, then subtract 2 to get 21.

For 2022, the requirement is 806

For 84942, the requirement is 33974

What is the total fuel requirement for your trip?

{{ if .Part1.Completed -}}

Congratulations! You got Part 1 correct. Your answer was {{ .Part1.Solution }}.

Part 2

Just before you about to take off, your copilot reminded you that you completely forgot to take into account the extra fuel needed for the fuel you already have! Just like your parting gifts, apply the same formula on the fuel to obtain the fuel needed for the fuel.

So, for each gift, calculate the fuel needed, treat that fuel as the mass itself, and calculate the fuel needed, and repeat this process until your fuel requirement reaches zero or a negative value.

Example

For a mass of 18, divide it by 2.5 and round down to get 7, then subtract 2 to get 5 as the fuel requirement. 5 divided by 2.5 gives you 1, and subtracting 2 gives you -1 so the total fuel required is still 5.

For a mass of 58, 21 fuel is used. Then, 21 needs 6 more fuel, and 6 requires no further fuel. The total fuel needed is 21+6 = 27

For 2022, the requirement is 806+320+126+48+17+4 = 1321

Using this new formula, what is the fuel total fuel requirements for all the mass, but also including the mass of the newly added fuel?

Calculate the requirements seperately, and them sum them together for each item.

{{ if .Part2.Completed -}}

Congratulations! You have completed both parts! The answer was {{ .Part2.Solution }}.

{{- end }} {{- end }}