package main import ( "bufio" "fmt" "io" ) func allzeros(ints []int) bool { for i := range ints { if ints[i] != 0 { return false } } return true } func nextOasis(previous int, start []int) int { if allzeros(start) { return 0 } length := len(start) - 1 levelBelow := make([]int, 0, length) for i := 0; i < length; i++ { levelBelow = append(levelBelow, start[i+1]-start[i]) } current := start[length] return current + nextOasis(current, levelBelow) } func previousOasis(previous int, start []int) int { return 0 } type day09 struct{} func (d day09) solve1(r io.Reader) string { scanner := bufio.NewScanner(r) total := 0 for scanner.Scan() { total += nextOasis(0, scanints(scanner.Text())) } return fmt.Sprintf("%d", total) } func (d day09) solve2(r io.Reader) string { scanner := bufio.NewScanner(r) total := 0 for scanner.Scan() { ints := scanints(scanner.Text()) reverseSlice(ints) total += nextOasis(0, ints) } return fmt.Sprintf("%d", total) }