Advent-of-Code/year25/day9/part2_mask.go
2025-12-24 22:25:20 +02:00

137 lines
3.4 KiB
Go

package day9
//)
//
//func Part2BF(ctx aoc.Context) (int, error) {
// g, err := geometry.ScannerToGrid(ctx.Scanner(), ",", strconv.Atoi)
// if err != nil {
// return 0, fmt.Errorf("day9: failed to parse intput %w", err)
// }
// points := geometry.UnsafeGridData(g)
//
// //data := g.Data()
// //
// //minx, miny := math.MaxInt, math.MaxInt
// //for i := range g.Rows() {
// // minx = min(data[i][0], minx)
// // miny = min(data[i][1], miny)
// //}
// //for i := range g.Rows() {
// // data[i][0] -= minx
// // data[i][1] -= miny
// // if data[i][1] == 0 {
// // fmt.Println()
// // }
// //}
// //g = geometry.GridFrom(data)
//
// bottomRight := []int{0, 0}
// for _, p := range points {
// bottomRight[colIndex] = max(bottomRight[colIndex], p[colIndex])
// bottomRight[lineIndex] = max(bottomRight[lineIndex], p[lineIndex])
// }
// bottomRight[colIndex] += 3
// bottomRight[lineIndex] += 2
//
// mask := geometry.NewGrid[byte](bottomRight[lineIndex], bottomRight[colIndex])
// //data := geometry.UnsafeGridData(mask)
// //for i := 0; i < mask.Rows(); i++ {
// // for j := 0; j < mask.Cols(); j++ {
// // data[i][j] = dot
// // }
// //}
// //mask.Fill(dot)
// for _, point := range points {
// p := geometry.NewPoint(point[lineIndex], point[colIndex])
// mask.Set(p, '#')
// }
//
// fillGrid := func(mask geometry.Grid[byte], start, end []int) {
// a := geometry.NewPoint(start[lineIndex], start[colIndex]).ToDirectional(0)
// b := geometry.NewPoint(end[lineIndex], end[colIndex]).ToDirectional(0)
//
// var d geometry.Direction
// if a.GetLine() == b.GetLine() {
// if a.GetCol() < b.GetCol() {
// d = geometry.DirectionRight
// } else {
// d = geometry.DirectionLeft
// }
// } else {
// if a.GetLine() < b.GetLine() {
// d = geometry.DirectionDown
// } else {
// d = geometry.DirectionUp
// }
// }
// a = a.SetDirection(d)
// b = b.SetDirection(d).MoveBackward()
//
// for a != b {
// a = a.MoveForward()
// mask.Set(a, 'X')
// }
// }
//
// var prev = points[len(points)-1]
// for i := 0; i < len(points); i++ {
// next := points[i]
// if prev[colIndex] == next[colIndex] || prev[lineIndex] == next[lineIndex] {
// fillGrid(mask, prev, next)
// } else {
// panic("day9: points out of range")
// }
// prev = next
// }
//
// stack := dsa.NewStack[geometry.Point]()
// for i, line := range geometry.UnsafeGridData(mask) {
// walls := 0
// for j, point := range line {
// if point == 'X' || point == '#' {
// walls += 1
// }
// if point == dot && walls == 1 {
// stack.Push(geometry.NewPoint(i, j))
// break
// }
// }
// if !stack.IsEmpty() {
// break
// }
// }
// for !stack.IsEmpty() {
// p := stack.Pop()
// if mask.At(p) == dot {
// mask.Set(p, 'Y')
// stack.Push(p.MoveUp())
// stack.Push(p.MoveLeft())
// stack.Push(p.MoveRight())
// stack.Push(p.MoveDown())
// }
// }
//
// for _, pair := range day9FindRectangles(points) {
// p1 := points[pair.Point1]
// p2 := points[pair.Point2]
//
// start := geometry.NewPoint(min(p1[lineIndex], p2[lineIndex]), min(p1[colIndex], p2[colIndex]))
// end := geometry.NewPoint(max(p1[lineIndex], p2[lineIndex]), max(p1[colIndex], p2[colIndex]))
//
// for i := start.Line; i <= end.Line; i++ {
// for j := start.Col; j <= end.Col; j++ {
// p := geometry.NewPoint(i, j)
// old := mask.At(p)
// mask.Set(p, '*')
// mask.Set(p, old)
// if mask.At(p) == dot {
// goto skip
// }
// }
// }
// return int(pair.Area), nil
// skip:
// }
// panic("day9: no solution found")
//}