blob: 3bd007baff5a19cbf89495457b2c28d081219881 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package main
import (
"bufio"
"fmt"
"os"
"git.adyxax.org/aoc/2021/05/line"
)
func main() {
matrix := make([][]int, 1000)
for i := 0; i < 1000; i++ {
matrix[i] = make([]int, 1000)
}
parser := line.NewParser(bufio.NewReader(os.Stdin))
for {
l, err := parser.Parse()
if err != nil {
break
}
if l.X1 == l.X2 {
if l.Y1 > l.Y2 {
l.Y1, l.Y2 = l.Y2, l.Y1
}
for i := l.Y1; i <= l.Y2; i++ {
matrix[l.X1][i]++
}
} else if l.Y1 == l.Y2 {
if l.X1 > l.X2 {
l.X1, l.X2 = l.X2, l.X1
}
for i := l.X1; i <= l.X2; i++ {
matrix[i][l.Y1]++
}
}
}
score := 0
for i := 0; i < 1000; i++ {
for j := 0; j < 1000; j++ {
if matrix[i][j] >= 2 {
score++
}
}
}
fmt.Println(score)
}
|