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 }