package main import ( "bufio" "fmt" "io" ) type day06 struct{} func (d day06) solve1(r io.Reader) string { buf := bufio.NewReader(r) values := make([][]int, 2) total := 1 for i := 0; i < 2; i++ { _, err := buf.ReadString(':') if err != nil { panic(err) } str, _ := buf.ReadString('\n') values[i] = scanints(str) } for i := 0; i < len(values[0]); i++ { time := values[0][i] record := values[1][i] wins := 0 for j := 0; j <= time; j++ { distance := ((time - j /*remaining time*/) * (j /*speed*/)) if distance > record { wins++ } } total *= wins wins = 0 } return fmt.Sprintf("%d", total) } func (d day06) solve2(r io.Reader) string { buf := bufio.NewReader(r) values := make([][]int, 2) total := 0 for i := 0; i < 2; i++ { _, err := buf.ReadString(':') if err != nil { panic(err) } str, _ := buf.ReadString('\n') values[i] = scanints(spaceReplacer.Replace(str)) } time := values[0][0] record := values[1][0] for i := 0; i < time; i++ { distance := (time - i) * i if distance > record { total++ } } return fmt.Sprintf("%d", total) }