no this isn't about alexandria ocasio-cortez
at main 82 lines 1.7 kB view raw
1package main 2 3import ( 4 "fmt" 5 "slices" 6 "strconv" 7 "strings" 8 9 "tangled.org/evan.jarrett.net/aoc2025/internal/puzzle" 10) 11 12type IDRange struct { 13 first int 14 last int 15} 16 17type DayFive struct { 18 freshIds []IDRange 19 tocheck []int 20} 21 22func (d *DayFive) ParseInput(input string) error { 23 for line := range strings.SplitSeq(strings.TrimSpace(input), "\n") { 24 line = strings.TrimSpace(line) 25 if strings.Contains(line, "-") { 26 splits := strings.Split(line, "-") 27 first, _ := strconv.Atoi(splits[0]) 28 last, _ := strconv.Atoi(splits[1]) 29 d.freshIds = append(d.freshIds, IDRange{first, last}) 30 } else if line == "" { 31 continue 32 } else { 33 ingredient, _ := strconv.Atoi(line) 34 d.tocheck = append(d.tocheck, ingredient) 35 } 36 } 37 return nil 38} 39 40func (d *DayFive) Part1() (int, error) { 41 count := 0 42 for _, i := range d.tocheck { 43 for _, idrange := range d.freshIds { 44 if i >= idrange.first && i <= idrange.last { 45 count++ 46 break 47 } 48 } 49 } 50 return count, nil 51} 52 53func (d *DayFive) Part2() (int, error) { 54 count := 0 55 56 slices.SortFunc(d.freshIds, func(a, b IDRange) int { 57 return a.first - b.first 58 }) 59 var combinedFreshIds []IDRange 60 last := d.freshIds[0] 61 for _, current := range d.freshIds { 62 if current.first <= last.last { 63 last.last = max(last.last, current.last) 64 } else { 65 combinedFreshIds = append(combinedFreshIds, last) 66 last = current 67 } 68 } 69 // combine one last time 70 combinedFreshIds = append(combinedFreshIds, last) 71 72 for _, idrange := range combinedFreshIds { 73 numInRange := idrange.last - idrange.first + 1 74 fmt.Println(numInRange) 75 count += numInRange 76 } 77 return count, nil 78} 79 80func main() { 81 puzzle.Run(5, &DayFive{}) 82}