Skip to content

Instantly share code, notes, and snippets.

@yurifedoseev
Created December 6, 2023 06:04
Show Gist options
  • Save yurifedoseev/14e10540eef62c88ae860c5739810543 to your computer and use it in GitHub Desktop.
Save yurifedoseev/14e10540eef62c88ae860c5739810543 to your computer and use it in GitHub Desktop.
func runPart() error {
start := time.Now()
filename := "day6//input.txt"
races, err := loadRace(filename)
if err != nil {
return err
}
waysComb := int64(1)
for _, race := range races {
waysComb *= calculus(race)
}
fmt.Printf("\nwaysComb %d", waysComb)
fmt.Printf("\nexecution time: %s", time.Since(start).String())
return nil
}
func calculus(race *Race) int64 {
// x*2 - race.Duration * x + race.RecordDistance
D := race.Duration*race.Duration - 4*race.RecordDistance
DSQRT := math.Sqrt(float64(D))
answer1 := int64((float64(race.Duration) + DSQRT) / 2)
fmt.Printf("\n answer1: %d", int(answer1))
answer2 := int64((float64(race.Duration) - DSQRT) / 2)
fmt.Printf("\n answer2: %d", int(answer2))
return max(answer2, answer1) - min(answer2, answer1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment