]> fbox.kageds.com Git - adventofcode.git/blobdiff - 2023/go/day05/day05.go
move unit64 back to int
[adventofcode.git] / 2023 / go / day05 / day05.go
index 902eb4367f2017e001af679b4674660cb673c398..39450e310d325914a4c4a8f945e6923a2063af8b 100644 (file)
@@ -37,7 +37,7 @@ func Part1(input string) int {
        fmt.Println(seeds)
        fmt.Println(almanac)
 
        fmt.Println(seeds)
        fmt.Println(almanac)
 
-       minLoc := utils.MaxInt
+       minLoc := int(utils.MaxInt)
        for _, seed := range seeds {
                soil := lookup_dest(seed, almanac.seed2soil)
                fert := lookup_dest(soil, almanac.soil2fert)
        for _, seed := range seeds {
                soil := lookup_dest(seed, almanac.seed2soil)
                fert := lookup_dest(soil, almanac.soil2fert)
@@ -57,53 +57,22 @@ func Part1(input string) int {
 
 func Part2(input string) int {
        seedsmap, almanac, _ := parseInput2(input)
 
 func Part2(input string) int {
        seedsmap, almanac, _ := parseInput2(input)
-       fmt.Println(seedsmap)
-       fmt.Println(almanac)
-       minLocMap := Map{dest_range_start: utils.MaxInt}
-       for _, x := range almanac.humid2loc {
-               if x.dest_range_start< minLocMap.dest_range_start {
-                       minLocMap = x
-               }
-       }
-       fmt.Println(minLocMap.dest_range_start)
 
 
-       for i:=minLocMap.src_range_start;i<minLocMap.src_range_start+minLocMap.range_len;i++ {
-               temp := lookup_src(i, almanac.temp2humid)
-               fmt.Println(temp)
+       for i:=0;i<utils.MaxInt;i++{
+               humid := lookup_src(int(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
+                       }
+               }
        }
        }
-
-//     minSeedMap := SeedMap{}
-//     minLoc := utils.MaxInt
-//     for _, seedmap := range seedsmap {
-//             for _, i := range []int{seedmap.seed, seedmap.seed+seedmap.range_len} {
-//                     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 {
-//                             minSeedMap = seedmap
-//                             minLoc = loc
-//                     }
-//             }
-//     }
-//     
-//     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 -1
 }
 
        return -1
 }
 
@@ -134,7 +103,7 @@ func parseInput1(input string) ([]int, Almanac, error) {
        seedLine := string(lines[0])
        tokens := strings.Fields(seedLine)
        for _, token := range tokens[1:] {
        seedLine := string(lines[0])
        tokens := strings.Fields(seedLine)
        for _, token := range tokens[1:] {
-                       seeds = append(seeds, utils.MustAtoi(token))
+                       seeds = append(seeds, int(utils.MustAtoi(token)))
        }
 
        blocks := strings.Split(input, "\n\n")
        }
 
        blocks := strings.Split(input, "\n\n")
@@ -171,8 +140,8 @@ func parseInput2(input string) ([]SeedMap, Almanac, error) {
        seedLine := string(lines[0])
        tokens := strings.Fields(seedLine)
        for i:=1;i<len(tokens);i=i+2 {
        seedLine := string(lines[0])
        tokens := strings.Fields(seedLine)
        for i:=1;i<len(tokens);i=i+2 {
-               seedStart := utils.MustAtoi(tokens[i])
-               seedRange := utils.MustAtoi(tokens[i+1])
+               seedStart := int(utils.MustAtoi(tokens[i]))
+               seedRange := int(utils.MustAtoi(tokens[i+1]))
                        seeds = append(seeds, SeedMap{seedStart, seedRange})
        }
 
                        seeds = append(seeds, SeedMap{seedStart, seedRange})
        }
 
@@ -205,7 +174,7 @@ func getMap(input []string) []Map {
        var out []Map
        for _, line := range input {
                tokens := strings.Fields(line)
        var out []Map
        for _, line := range input {
                tokens := strings.Fields(line)
-               out = append(out, Map{utils.MustAtoi(tokens[0]), utils.MustAtoi(tokens[1]),utils.MustAtoi(tokens[2])})
+               out = append(out, Map{int(utils.MustAtoi(tokens[0])), int(utils.MustAtoi(tokens[1])),int(utils.MustAtoi(tokens[2]))})
        }
        return out
 }
\ No newline at end of file
        }
        return out
 }
\ No newline at end of file