no this isn't about alexandria ocasio-cortez
at main 85 lines 1.6 kB view raw
1package main 2 3import ( 4 "log/slog" 5 "strconv" 6 "strings" 7 8 "tangled.org/evan.jarrett.net/aoc2025/internal/puzzle" 9) 10 11type ProductId struct { 12 firstId int 13 lastId int 14} 15 16type DayTwo struct { 17 productIds []ProductId 18} 19 20func (d *DayTwo) ParseInput(input string) error { 21 for productId := range strings.SplitSeq(strings.TrimSpace(input), ",") { 22 productId = strings.TrimSpace(productId) 23 if productId == "" { 24 continue 25 } 26 parts := strings.Split(productId, "-") 27 first, _ := strconv.Atoi(parts[0]) 28 last, _ := strconv.Atoi(parts[1]) 29 30 product := ProductId{ 31 firstId: first, 32 lastId: last, 33 } 34 35 d.productIds = append(d.productIds, product) 36 } 37 return nil 38} 39 40func findPattern(productId int, j int) int { 41 s := strconv.Itoa(productId) 42 n := len(s) 43 if n%j == 0 { 44 piece := s[:n/j] 45 if strings.Repeat(piece, j) == s { 46 slog.Debug("found invalid ID", "id", s) 47 return productId 48 } 49 } 50 return 0 51} 52 53// find ids that have a repeating pattern. 55 = 5 twice, 6464 = 64 twice. 54func (d *DayTwo) Part1() (int, error) { 55 sum := 0 56 for _, product := range d.productIds { 57 for i := product.firstId; i <= product.lastId; i++ { 58 sum += findPattern(i, 2) 59 } 60 } 61 62 return sum, nil 63} 64 65func (d *DayTwo) Part2() (int, error) { 66 sum := 0 67 for _, product := range d.productIds { 68 for i := product.firstId; i <= product.lastId; i++ { 69 s := strconv.Itoa(i) 70 n := len(s) 71 for j := 2; j <= n; j++ { 72 if result := findPattern(i, j); result > 0 { 73 sum += result 74 break 75 } 76 } 77 } 78 } 79 80 return sum, nil 81} 82 83func main() { 84 puzzle.Run(2, &DayTwo{}) 85}