Created
December 6, 2023 06:04
-
-
Save yurifedoseev/14e10540eef62c88ae860c5739810543 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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