]> git.sommitrealweird.co.uk Git - advent-of-code-2019.git/blob - day01/get_fuel_required.sh
Day 15
[advent-of-code-2019.git] / day01 / get_fuel_required.sh
1 #!/bin/bash
2
3 filename=${1:-input.txt}
4
5 exec 3<"$filename"
6
7 fuel_total=0
8 fuel_and_extra=0
9 while read -u 3 mass; do
10     fuel=$((($mass / 3) - 2))
11     fuel_total=$((fuel_total+$fuel))
12     fuel_and_extra=$((fuel_and_extra+$fuel))
13     extra_fuel=$((($fuel / 3) - 2))
14     while [ $extra_fuel -gt 0 ]; do
15         fuel_and_extra=$((fuel_and_extra+$extra_fuel))
16         extra_fuel=$((($extra_fuel / 3) - 2))
17     done
18 done
19
20 echo $fuel_total
21 echo $fuel_and_extra