mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-22 10:20:48 +00:00
49 lines
982 B
Go
49 lines
982 B
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var identifiers = []string{"seed-to-soil", "soil-to-fertilizer", "fertilizer-to-water", "water-to-light", "light-to-temperature", "temperature-to-humidity", "humidity-to-location"}
|
|
|
|
func next(i int, datapoint int) int {
|
|
if i == len(identifiers) {
|
|
return datapoint
|
|
}
|
|
|
|
dest := func() int {
|
|
datas := dataMap[identifiers[i]]
|
|
dest := 0
|
|
for _, data := range datas {
|
|
if datapoint >= data.source && datapoint <= data.source+data.offset {
|
|
dest = data.dest + (datapoint - data.source)
|
|
break
|
|
}
|
|
}
|
|
if dest == 0 {
|
|
dest = datapoint
|
|
}
|
|
return dest
|
|
}()
|
|
//log.Debug(identifiers[i], ": ", dest)
|
|
return next(i+1, dest)
|
|
}
|
|
|
|
// one returns the lowest location
|
|
func one(lines []string) (int, error) {
|
|
lowest := math.MaxInt
|
|
parseLines(lines)
|
|
|
|
for _, seed := range seeds {
|
|
location := next(0, seed)
|
|
log.Info(location)
|
|
if location < lowest {
|
|
lowest = location
|
|
}
|
|
}
|
|
|
|
return lowest, nil
|
|
}
|