@@ -11,12 +11,12 @@ import (
11
11
func main () {
12
12
facts , rules := parseInput ()
13
13
14
- // GenerateDot(rules)
15
- // return
14
+ //GenerateDot(rules)
15
+ //return
16
16
17
17
// After generating the dot file, I could generate an image with
18
18
//
19
- // dot -Tpng -O graph.dot
19
+ // dot -Tsvg -O graph.dot
20
20
//
21
21
// and thanks to the colors of the arrows, it was easy to spot inconsistencies.
22
22
// E.g.
@@ -50,10 +50,14 @@ func main() {
50
50
// - z19 <> cph (they are both in the z19 area)
51
51
// - z33 <> hgj (they are both in the z33 area)
52
52
53
- swap ("z13" , "npf" , rules )
54
- swap ("z33" , "hgj" , rules )
55
- swap ("gws" , "nnt" , rules )
56
- swap ("z19" , "cph" , rules )
53
+ swap := func (r1 , r2 string ) {
54
+ rules [r1 ], rules [r2 ] = rules [r2 ], rules [r1 ]
55
+ }
56
+ swap ("z13" , "npf" )
57
+ swap ("z33" , "hgj" )
58
+ swap ("gws" , "nnt" )
59
+ swap ("z19" , "cph" )
60
+
57
61
x := GetNumber ("x" , facts , rules )
58
62
y := GetNumber ("y" , facts , rules )
59
63
z := GetNumber ("z" , facts , rules )
@@ -67,42 +71,32 @@ func main() {
67
71
// Sum is working = true
68
72
}
69
73
70
- func swap (r1 , r2 string , rules map [string ]Rule ) {
71
- rules [r1 ], rules [r2 ] = rules [r2 ], rules [r1 ]
72
- }
73
-
74
74
func GenerateDot (rules map [string ]Rule ) {
75
75
f , err := os .Create ("graph.dot" )
76
76
if err != nil {
77
77
log .Fatal (err )
78
78
}
79
79
defer f .Close ()
80
80
81
- const Size = 45
81
+ color := map [string ]string {
82
+ "XOR" : "red" ,
83
+ "AND" : "blue" ,
84
+ "OR" : "green" ,
85
+ }
86
+
82
87
fmt .Fprint (f , "digraph {\n " )
83
88
for rName , r := range rules {
84
- var color string
85
- switch r .Op {
86
- case "XOR" :
87
- color = "red"
88
- case "AND" :
89
- color = "blue"
90
- case "OR" :
91
- color = "green"
92
- }
93
-
94
- fmt .Fprintf (f , "%s -> %s [color=\" %s\" ];\n " , r .Left , rName , color )
95
- fmt .Fprintf (f , "%s -> %s [color=\" %s\" ];\n " , r .Right , rName , color )
89
+ fmt .Fprintf (f , "%s -> %s [color=\" %s\" ];\n " , r .Left , rName , color [r .Op ])
90
+ fmt .Fprintf (f , "%s -> %s [color=\" %s\" ];\n " , r .Right , rName , color [r .Op ])
96
91
}
97
92
98
- var xs , ys , zs []string
99
- for i := 0 ; i < Size ; i ++ {
100
- xs = append (xs , fmt .Sprintf ("x%02d" , i ))
101
- ys = append (ys , fmt .Sprintf ("y%02d" , i ))
93
+ var xys , zs []string
94
+ for i := 0 ; i <= 45 ; i ++ {
95
+ xys = append (xys , fmt .Sprintf ("x%02d" , i ))
96
+ xys = append (xys , fmt .Sprintf ("y%02d" , i ))
102
97
zs = append (zs , fmt .Sprintf ("z%02d" , i ))
103
98
}
104
- fmt .Fprintf (f , "{rank = min;\n %s ; \n };\n " , strings .Join (xs , " -> " ))
105
- fmt .Fprintf (f , "{rank = min;\n %s ; \n };\n " , strings .Join (ys , " -> " ))
99
+ fmt .Fprintf (f , "{rank = min;\n %s ; \n };\n " , strings .Join (xys , " -> " ))
106
100
fmt .Fprintf (f , "{rank = max;\n %s ; \n };\n " , strings .Join (zs , " -> " ))
107
101
fmt .Fprint (f , "}\n " )
108
102
}
0 commit comments