File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change 44 "bufio"
55 "log"
66 "os"
7+ "strings"
78)
89
910func main () {
@@ -20,5 +21,43 @@ func main() {
2021}
2122
2223func calculateOrbitConnections (input []string ) int {
23- return 0
24+
25+ connections := 0
26+
27+ for i := len (input ) - 1 ; i >= 0 ; i -- {
28+ r := strings .Split (strings .TrimSpace (input [i ]), ")" )
29+ //a := r[0]
30+ b := strings .TrimSpace (r [0 ])
31+
32+ connections ++
33+
34+ // log.Printf("direct %v", r)
35+
36+ offset := 0
37+
38+ next := i - 1
39+
40+ for ii := next ; ii >= 0 ; ii -- {
41+
42+ r := strings .Split (input [ii ], ")" )
43+
44+ for iii := next - offset ; iii >= 0 ; iii -- {
45+
46+ r := strings .Split (input [iii ], ")" )
47+
48+ log .Printf ("checking if %s is %s" , r [1 ], b )
49+
50+ if strings .TrimSpace (r [1 ]) == b {
51+ log .Printf ("indirect %v" , r )
52+ connections ++
53+ }
54+ }
55+
56+ b = strings .TrimSpace (r [0 ])
57+ offset = 1
58+ }
59+
60+ }
61+
62+ return connections
2463}
You can’t perform that action at this time.
0 commit comments