-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06p2.go
43 lines (32 loc) · 859 Bytes
/
06p2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"strconv"
"aoc2023/utils"
)
func D06P2() {
lines := utils.ReadLines("inputs/06.txt")
boatRace := parseBoatRacesPartTwo(lines)
possibleWinningScenarios := findBoatRaceWins(boatRace)
fmt.Printf("Possible winning scenarios: %d\n", possibleWinningScenarios)
}
func parseBoatRacesPartTwo(lines []string) boatRace {
race := boatRace{}
// Parse time
timeDigitString := ""
for _, timeDigit := range lines[0] {
if timeDigit >= '0' && timeDigit <= '9' {
timeDigitString += string(timeDigit)
}
}
race.time, _ = strconv.Atoi(timeDigitString)
distanceDigitString := ""
// Parse distance
for _, distanceDigit := range lines[1] {
if distanceDigit >= '0' && distanceDigit <= '9' {
distanceDigitString += string(distanceDigit)
}
}
race.distanceRecord, _ = strconv.Atoi(distanceDigitString)
return race
}