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.

main.go 652B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/csmith/aoc-2019/common"
  5. "strconv"
  6. )
  7. func fuel(mass int) int {
  8. return (mass / 3) - 2
  9. }
  10. func fuelRequirements(input []string) (int, int) {
  11. var (
  12. simpleTotal = 0
  13. recursiveTotal = 0
  14. )
  15. for _, line := range input {
  16. mass, err := strconv.Atoi(line)
  17. if err != nil {
  18. panic(err)
  19. }
  20. required := fuel(mass)
  21. simpleTotal += required
  22. for required > 0 {
  23. recursiveTotal += required
  24. required = fuel(required)
  25. }
  26. }
  27. return simpleTotal, recursiveTotal
  28. }
  29. func main() {
  30. input := common.ReadLines("01/input.txt")
  31. part1, part2 := fuelRequirements(input)
  32. fmt.Println(part1)
  33. fmt.Println(part2)
  34. }