day5 part2

This commit is contained in:
2023-12-06 13:48:16 +00:00
parent 34e8893d31
commit 204e001459
2 changed files with 21 additions and 30 deletions

View File

@@ -58,39 +58,22 @@ func Part1(input string) uint64 {
func Part2(input string) int {
seedsmap, almanac, _ := parseInput2(input)
for i:=0;i<utils.MaxInt;i++{
humid := lookup_src(uint64(i), almanac.humid2loc)
temp := lookup_src(humid, almanac.temp2humid)
light := lookup_src(temp, almanac.light2temp)
water := lookup_src(light, almanac.water2light)
fert := lookup_src(water, almanac.fert2water)
soil := lookup_src(fert, almanac.soil2fert)
seed := lookup_src(soil, almanac.seed2soil)
minLoc := uint64(utils.MaxInt)
for _, seedmap := range seedsmap {
for i := seedmap.seed;i<seedmap.seed+seedmap.range_len;i++ {
soil := lookup_dest(i, almanac.seed2soil)
fert := lookup_dest(soil, almanac.soil2fert)
water := lookup_dest(fert, almanac.fert2water)
light := lookup_dest(water, almanac.water2light)
temp := lookup_dest(light, almanac.light2temp)
humid := lookup_dest(temp, almanac.temp2humid)
loc := lookup_dest(humid, almanac.humid2loc)
if loc < minLoc {
minLoc = loc
for _, seedmap := range seedsmap {
if seed >= seedmap.seed && seed < seedmap.seed+seedmap.range_len {
return i
}
}
fmt.Println(minLoc)
}
//
// fmt.Println(minSeedMap)
// minLoc = utils.MaxInt
// for i:=minSeedMap.seed;i<minSeedMap.seed+minSeedMap.range_len;i++ {
// soil := lookup_dest(i, almanac.seed2soil)
// fert := lookup_dest(soil, almanac.soil2fert)
// water := lookup_dest(fert, almanac.fert2water)
// light := lookup_dest(water, almanac.water2light)
// temp := lookup_dest(light, almanac.light2temp)
// humid := lookup_dest(temp, almanac.temp2humid)
// loc := lookup_dest(humid, almanac.humid2loc)
// if loc < minLoc {
// minLoc = loc
// }
// }
return int(minLoc)
return -1
}
func lookup_dest(entity uint64, data []Map) uint64 {