Report abuse

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
--- triangle.c	2011-03-22 08:36:36.473333340 -0400
+++ mac.c	2011-03-22 08:36:24.816666672 -0400
@@ -32,19 +32,25 @@
 /* builds all possible triangles */
 int main(int argc, char *argv[])
 {
-  unsigned short x, bitop, mask;
+
+  /* figure = sequential ID for the figure we're drawing
+     edge = sequential ID for the edge of the figure, which we may or may not draw */
+  unsigned short figure, edge;
+
   CONNECTIONS = connections(VERTICES);
   POSSIBILITIES = (unsigned short) pow(2, CONNECTIONS);

-  for (x = 0; x < POSSIBILITIES; x++)
+  /* iterate over total possible figures */
+  for (figure = 0; figure < POSSIBILITIES; figure++)
   {
     printf("%s\n", baseSvg);
-    for (bitop = 0; bitop < CONNECTIONS; bitop++)
-    {
-      mask = ((unsigned short) pow(2, bitop)) & x;
-      if (mask > 0)
+    /* in this figure, consider each potential edge */
+    for (edge = 0; edge < CONNECTIONS; edge++) {
+      /* is the edge's bit a 1 in the figure ID? */
+      if ((unsigned short) (1 << edge) & figure)
       {
-        printf("%s\n", lines[bitop]);
+      	/* if so, draw it. */
+        printf("%s\n", lines[edge]);
       }
     }
     printf("%s\n\n", endSvg);