@@ -11,12 +11,12 @@ import (
1111func main () {
1212 facts , rules := parseInput ()
1313
14- // GenerateDot(rules)
15- // return
14+ //GenerateDot(rules)
15+ //return
1616
1717 // After generating the dot file, I could generate an image with
1818 //
19- // dot -Tpng -O graph.dot
19+ // dot -Tsvg -O graph.dot
2020 //
2121 // and thanks to the colors of the arrows, it was easy to spot inconsistencies.
2222 // E.g.
@@ -50,10 +50,14 @@ func main() {
5050 // - z19 <> cph (they are both in the z19 area)
5151 // - z33 <> hgj (they are both in the z33 area)
5252
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+
5761 x := GetNumber ("x" , facts , rules )
5862 y := GetNumber ("y" , facts , rules )
5963 z := GetNumber ("z" , facts , rules )
@@ -67,42 +71,32 @@ func main() {
6771 // Sum is working = true
6872}
6973
70- func swap (r1 , r2 string , rules map [string ]Rule ) {
71- rules [r1 ], rules [r2 ] = rules [r2 ], rules [r1 ]
72- }
73-
7474func GenerateDot (rules map [string ]Rule ) {
7575 f , err := os .Create ("graph.dot" )
7676 if err != nil {
7777 log .Fatal (err )
7878 }
7979 defer f .Close ()
8080
81- const Size = 45
81+ color := map [string ]string {
82+ "XOR" : "red" ,
83+ "AND" : "blue" ,
84+ "OR" : "green" ,
85+ }
86+
8287 fmt .Fprint (f , "digraph {\n " )
8388 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 ])
9691 }
9792
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 ))
10297 zs = append (zs , fmt .Sprintf ("z%02d" , i ))
10398 }
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 , " -> " ))
106100 fmt .Fprintf (f , "{rank = max;\n %s ; \n };\n " , strings .Join (zs , " -> " ))
107101 fmt .Fprint (f , "}\n " )
108102}
0 commit comments