Days 7,8,9
This commit is contained in:
40
2023/gareth/day07/day07.go
Normal file
40
2023/gareth/day07/day07.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package day06
|
||||
|
||||
type Race struct {
|
||||
Time int
|
||||
Distance int
|
||||
}
|
||||
|
||||
func Part1(input string) int {
|
||||
var Races []Race
|
||||
Races = append(Races, Race{56, 546})
|
||||
Races = append(Races, Race{97, 1927})
|
||||
Races = append(Races, Race{78, 1131})
|
||||
Races = append(Races, Race{75, 1139})
|
||||
|
||||
total := 1
|
||||
for _, r := range Races {
|
||||
halfTime := r.Time / 2
|
||||
for i := 0; i <= halfTime; i++ {
|
||||
raceDis := i * (r.Time - i)
|
||||
if raceDis > r.Distance {
|
||||
total = total * (r.Time - (i * 2) + 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func Part2(input string) int {
|
||||
r := Race{56977875, 546192711311139}
|
||||
halfTime := r.Time / 2
|
||||
for i := 0; i <= halfTime; i++ {
|
||||
raceDis := i * (r.Time - i)
|
||||
if raceDis > r.Distance {
|
||||
return r.Time - (i * 2) + 1
|
||||
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
16
2023/gareth/day07/day07_test.go
Normal file
16
2023/gareth/day07/day07_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package day06
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPart1(t *testing.T) {
|
||||
r := Part1(``)
|
||||
assert.Equal(t, 1624896, r)
|
||||
}
|
||||
|
||||
func TestPart2(t *testing.T) {
|
||||
r := Part2(``)
|
||||
assert.Equal(t, 32583852, r)
|
||||
}
|
||||
1000
2023/gareth/day07/input.txt
Normal file
1000
2023/gareth/day07/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user