day5 part2
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"adventofcode2023/day02"
|
||||
"adventofcode2023/day03"
|
||||
"adventofcode2023/day04"
|
||||
"adventofcode2023/day05"
|
||||
"adventofcode2023/day06"
|
||||
)
|
||||
// Usage: go run main.go <NN>
|
||||
// assumes input is in day<NN>/input.txt
|
||||
@@ -31,6 +33,12 @@ func main() {
|
||||
case 4:
|
||||
fmt.Printf("part 1: %d\n", day04.Part1(utils.Readfile(d)))
|
||||
fmt.Printf("part 2: %d\n", day04.Part2(utils.Readfile(d)))
|
||||
case 5:
|
||||
fmt.Printf("part 1: %d\n", day05.Part1(utils.Readfile(d)))
|
||||
fmt.Printf("part 2: %d\n", day05.Part2(utils.Readfile(d)))
|
||||
case 6:
|
||||
fmt.Printf("part 1: %d\n", day06.Part1(utils.Readfile(d)))
|
||||
fmt.Printf("part 2: %d\n", day06.Part2(utils.Readfile(d)))
|
||||
default:
|
||||
panic(fmt.Errorf("no such day: %d", d))
|
||||
}
|
||||
@@ -38,7 +46,7 @@ func main() {
|
||||
|
||||
// Reads day from os.Args.
|
||||
func day() int {
|
||||
latest := 3
|
||||
latest := 5
|
||||
if len(os.Args) == 1 {
|
||||
return latest
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user