]> fbox.kageds.com Git - adventofcode.git/commitdiff
day5 part2
authorAlan R Evans <alan@kageds.com>
Wed, 6 Dec 2023 13:48:16 +0000 (13:48 +0000)
committerAlan R Evans <alan@kageds.com>
Wed, 6 Dec 2023 13:48:16 +0000 (13:48 +0000)
2023/go/day05/day05.go
2023/go/main.go

index ec4698abe7ecd8811057c571d71a5133543b20e3..202bfaa3c7231828c96ac5b48d30d7c8cfea5555 100644 (file)
@@ -58,39 +58,22 @@ func Part1(input string) uint64 {
 func Part2(input string) int {
        seedsmap, almanac, _ := parseInput2(input)
 
 func Part2(input string) int {
        seedsmap, almanac, _ := parseInput2(input)
 
-
-       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 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)
+
+               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 {
 }
 
 func lookup_dest(entity uint64, data []Map) uint64 {
index 0f19aeb50405e509bf10f950f06d52b0c8711f52..dbfddc1558713b7226185bb4ace987b8979a63be 100644 (file)
@@ -11,6 +11,8 @@ import (
        "adventofcode2023/day02"
        "adventofcode2023/day03"
        "adventofcode2023/day04"
        "adventofcode2023/day02"
        "adventofcode2023/day03"
        "adventofcode2023/day04"
+       "adventofcode2023/day05"
+       "adventofcode2023/day06"
 )
 // Usage: go run main.go <NN>
 // assumes input is in day<NN>/input.txt
 )
 // 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 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))
        }
        default:
                panic(fmt.Errorf("no such day: %d", d))
        }
@@ -38,7 +46,7 @@ func main() {
 
 // Reads day from os.Args.
 func day() int {
 
 // Reads day from os.Args.
 func day() int {
-       latest := 3
+       latest := 5
        if len(os.Args) == 1 {
                return latest
        }
        if len(os.Args) == 1 {
                return latest
        }