You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
633 B

package main
import (
"fmt"
"math"
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := helpers.StdinToStringSlice()
fmt.Println("Fuel Required:", part1(inp))
}
func part1(inp []string) int {
var total int
for _, v := range inp {
total = total + part2(fuelRequired(float64(helpers.Atoi(v))))
}
return total
}
func part2(fuel int) int {
ret := fuel
for fuel > 0 {
fuel = fuelRequired(float64(fuel))
fmt.Println(fuel)
ret = ret + fuel
}
return ret
}
func fuelRequired(mass float64) int {
res, _ := math.Modf(mass / 3)
if int(res)-2 < 0 {
return 0
}
return int(res) - 2
}