50 lines
947 B
Go
50 lines
947 B
Go
package day05
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"regexp"
|
|
"strconv"
|
|
|
|
utils "git.anthonygueguen.fr/g3po/aoc2023/internal"
|
|
)
|
|
|
|
func GetShortestLocation(content []string) int64 {
|
|
seeds := make(map[int64]int64)
|
|
minLocation := int64(math.MaxInt64)
|
|
re := regexp.MustCompile(`\d+`)
|
|
for _, val := range re.FindAllString(content[0], -1) {
|
|
num := utils.Must(strconv.ParseInt(val, 10, 64))
|
|
seeds[num] = num
|
|
}
|
|
|
|
for i := 1; i < len(content); i++ {
|
|
matches := re.FindAllString(content[i], -1)
|
|
if len(matches) != 3 {
|
|
continue
|
|
}
|
|
fmt.Println(seeds)
|
|
fmt.Println(matches)
|
|
var num []int64
|
|
for _, val := range matches {
|
|
num = append(num, utils.Must(strconv.ParseInt(val, 10, 64)))
|
|
}
|
|
|
|
for k, v := range seeds {
|
|
if v >= num[1] && v < num[1]+num[2] {
|
|
seeds[k] = num[0] + (v - num[1])
|
|
}
|
|
}
|
|
|
|
}
|
|
for _, v := range seeds {
|
|
if v < minLocation {
|
|
minLocation = v
|
|
}
|
|
}
|
|
return minLocation
|
|
}
|
|
|
|
func contentToBlock(content []string) {
|
|
}
|