mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
50 lines
1007 B
Go
50 lines
1007 B
Go
package main
|
|
|
|
import (
|
|
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 := 0
|
|
parseLines(lines)
|
|
|
|
for _, seed := range seeds {
|
|
location := next(0, seed)
|
|
log.Info(location)
|
|
if lowest == 0 {
|
|
lowest = location
|
|
}
|
|
if location < lowest {
|
|
lowest = location
|
|
}
|
|
}
|
|
|
|
return lowest, nil
|
|
}
|