-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask12.go
57 lines (46 loc) · 909 Bytes
/
task12.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
package main
import (
"fmt"
"strconv"
"strings"
"github.com/LaurenceUsas/advent-of-code-2017/helpers"
)
/*
0 <-> 2
1 <-> 1
2 <-> 0, 3, 4
3 <-> 2, 4
4 <-> 2, 3, 6
5 <-> 6
6 <-> 4, 5
*/
var input []string
var idsInGroup = map[int]bool{}
//Task12 Solution
func Task12() {
input = helpers.InputFile("./Task12/input.txt")
fmt.Printf("[Part 1 answer] - %v\n", task12PartOne(input, 0))
}
func task12PartOne(input []string, id int) int {
generateGroup(id)
return len(idsInGroup)
}
func generateGroup(id int) {
idsInGroup[id] = true
l := input[id] //line
e := strings.Split(l, " ") //elements
for _, v := range e[2:] {
str := strings.Trim(v, ",")
val, _ := strconv.Atoi(str)
//add to ID to check.
if _, ok := idsInGroup[val]; !ok {
generateGroup(val)
}
}
}
func part2(input []string, id int) int {
for len(input) != 0 {
}
generateGroup(id)
return len(idsInGroup)
}