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 583B

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