🎅 2025 Day 12 Complete! 🎄
This commit is contained in:
78
2025/day12/main.go
Normal file
78
2025/day12/main.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
inp := h.StdinToStringSlice()
|
||||
part1(inp)
|
||||
fmt.Println()
|
||||
part2(inp)
|
||||
}
|
||||
|
||||
func part1(inp []string) {
|
||||
p, r := parseInput(inp)
|
||||
|
||||
var acc int
|
||||
for i := range r {
|
||||
area := r[i].x * r[i].y
|
||||
size := 0
|
||||
for j := range r[i].req {
|
||||
size += r[i].req[j] * p[j].area
|
||||
}
|
||||
if area > size {
|
||||
acc++
|
||||
}
|
||||
}
|
||||
fmt.Println("Part 1")
|
||||
fmt.Println(p)
|
||||
fmt.Println(acc)
|
||||
}
|
||||
|
||||
func part2(inp []string) {
|
||||
}
|
||||
|
||||
type Region struct {
|
||||
x, y int
|
||||
req []int
|
||||
}
|
||||
type Present struct {
|
||||
area int
|
||||
}
|
||||
|
||||
func BuildPresent(inp []string) Present {
|
||||
area := 0
|
||||
for _, row := range inp {
|
||||
area += bytes.Count([]byte(row), []byte{'#'})
|
||||
}
|
||||
return Present{area: area}
|
||||
}
|
||||
|
||||
func parseInput(inp []string) ([]Present, []Region) {
|
||||
// All presents are 3x3, we have 6 of them
|
||||
var presents []Present
|
||||
var regions []Region
|
||||
for i := 0; i < 30; i += 5 {
|
||||
if len(presents) == 6 {
|
||||
break
|
||||
}
|
||||
presents = append(presents, BuildPresent(inp[i+1:i+4]))
|
||||
}
|
||||
|
||||
for i := 30; i < len(inp); i++ {
|
||||
// Parse regions
|
||||
r := Region{}
|
||||
var p0, p1, p2, p3, p4, p5 int
|
||||
fmt.Sscanf(
|
||||
inp[i], "%dx%d: %d %d %d %d %d %d",
|
||||
&r.x, &r.y, &p0, &p1, &p2, &p3, &p4, &p5,
|
||||
)
|
||||
r.req = []int{p0, p1, p2, p3, p4, p5}
|
||||
regions = append(regions, r)
|
||||
}
|
||||
return presents, regions
|
||||
}
|
||||
Reference in New Issue
Block a user