no this isn't about alexandria ocasio-cortez
at main 2.0 kB view raw
1package main 2 3import ( 4 "strings" 5 6 "tangled.org/evan.jarrett.net/aoc2025/internal/puzzle" 7) 8 9type PaperRoll struct { 10 row int 11 column int 12 left int 13 right int 14 up int 15 upLeft int 16 upRight int 17 down int 18 downLeft int 19 downRight int 20} 21 22func (p *PaperRoll) CanAccess() bool { 23 return p.left+p.right+p.up+p.down+p.upLeft+p.upRight+p.downLeft+p.downRight < 4 24} 25 26type DayFour struct { 27 grid []string 28 rolls []PaperRoll 29} 30 31const rollchar byte = '@' 32 33func getCell(grid []string, i, j int) int { 34 if i < 0 || i >= len(grid) || j < 0 || j >= len(grid[i]) { 35 return 0 36 } 37 if grid[i][j] == rollchar { 38 return 1 39 } 40 return 0 41} 42 43func (d *DayFour) ParseInputArr(input []string) { 44 for i, line := range d.grid { 45 line = strings.TrimSpace(line) 46 if line == "" { 47 continue 48 } 49 for j, ch := range line { 50 if ch == rune(rollchar) { 51 p := PaperRoll{ 52 row: i, 53 column: j, 54 left: getCell(d.grid, i, j-1), 55 right: getCell(d.grid, i, j+1), 56 up: getCell(d.grid, i-1, j), 57 upLeft: getCell(d.grid, i-1, j-1), 58 upRight: getCell(d.grid, i-1, j+1), 59 down: getCell(d.grid, i+1, j), 60 downLeft: getCell(d.grid, i+1, j-1), 61 downRight: getCell(d.grid, i+1, j+1), 62 } 63 d.rolls = append(d.rolls, p) 64 } 65 } 66 } 67} 68 69func (d *DayFour) ParseInput(input string) error { 70 d.grid = strings.Split(strings.TrimSpace(input), "\n") 71 d.ParseInputArr(d.grid) 72 return nil 73} 74 75func (d *DayFour) Part1() (int, error) { 76 count := 0 77 for _, roll := range d.rolls { 78 if roll.CanAccess() { 79 count++ 80 } 81 } 82 return count, nil 83} 84 85func (d *DayFour) Part2() (int, error) { 86 count := 0 87 changed := true 88 89 for changed { 90 changed = false 91 d.rolls = nil 92 d.ParseInputArr(d.grid) 93 94 for _, roll := range d.rolls { 95 if roll.CanAccess() { 96 d.grid[roll.row] = d.grid[roll.row][:roll.column] + "." + d.grid[roll.row][roll.column+1:] 97 count++ 98 changed = true 99 } 100 } 101 } 102 return count, nil 103} 104 105func main() { 106 puzzle.Run(4, &DayFour{}) 107}