-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3.go
47 lines (45 loc) · 876 Bytes
/
day3.go
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
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
)
func (x Aoc) Day3(scanner *bufio.Scanner) {
r := regexp.MustCompile(`\#(\d+) \@ (\d+),(\d+): (\d+)x(\d+)`)
var m [1002004]int64
var clean [4096]bool
z := 0
for scanner.Scan() {
g := r.FindStringSubmatch(scanner.Text())
id, _ := strconv.ParseInt(g[1], 10, 0)
x, _ := strconv.ParseInt(g[2], 10, 0)
y, _ := strconv.ParseInt(g[3], 10, 0)
w, _ := strconv.ParseInt(g[4], 10, 0)
h, _ := strconv.ParseInt(g[5], 10, 0)
clean[id] = true
for j := int64(0); j < h; j++ {
o := (y+j)*1000 + x
for i := int64(0); i < w; i++ {
if m[o+i] == 0 {
m[o+i] = id
} else {
clean[id] = false
if m[o+i] > 0 {
clean[m[o+i]] = false
m[o+i] = -1
z++
}
}
}
}
}
fmt.Println(z)
for p, v := range clean {
if v {
fmt.Println(p)
os.Exit(0)
}
}
}