-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday18.go
61 lines (51 loc) · 1.04 KB
/
day18.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"math"
"os"
"strconv"
"strings"
)
type Cube struct {
x int
y int
z int
}
func is_adjacent(a Cube, b Cube) bool {
x_dist := int(math.Abs(float64(a.x) - float64(b.x)))
y_dist := int(math.Abs(float64(a.y) - float64(b.y)))
z_dist := int(math.Abs(float64(a.z) - float64(b.z)))
if x_dist+y_dist+z_dist == 1 {
return true
}
return false
}
func main() {
input, _ := os.ReadFile("./input/input18.txt")
var cubes []Cube
lines := strings.Split(string(input), "\r\n")
for _, line := range lines {
broken := strings.Split(line, ",")
x, _ := strconv.Atoi(broken[0])
y, _ := strconv.Atoi(broken[1])
z, _ := strconv.Atoi(broken[2])
cubes = append(cubes, Cube{x, y, z})
}
//fmt.Println(cubes)
part1 := 0
adjacent_faces := 0
for i := 0; i < len(cubes); i++ {
adjacent_faces = 0
for j := 0; j < len(cubes); j++ {
if i == j {
continue
}
if is_adjacent(cubes[i], cubes[j]) {
adjacent_faces++
}
}
part1 += 6 - adjacent_faces
}
fmt.Println("Part 1:", part1)
fmt.Println("Part 2:", 0)
}