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