2023-12-06 04:01:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-06 16:55:59 +00:00
|
|
|
"math"
|
|
|
|
|
2023-12-06 04:01:17 +00:00
|
|
|
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) {
|
2023-12-06 16:55:59 +00:00
|
|
|
lowest := math.MaxInt
|
2023-12-06 04:01:17 +00:00
|
|
|
parseLines(lines)
|
|
|
|
|
|
|
|
for _, seed := range seeds {
|
|
|
|
location := next(0, seed)
|
|
|
|
log.Info(location)
|
|
|
|
if location < lowest {
|
|
|
|
lowest = location
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lowest, nil
|
|
|
|
}
|