package etomica.graph.util;

import etomica.graph.model.Bitmap;
import etomica.graph.model.BitmapFactory;
import etomica.graph.model.Graph;
import etomica.graph.model.GraphFactory;


public class GraphNumber {

  public static void main(String[] args) {
    String usage = "usage: GraphNumber n";
    if (args.length == 0) {
      System.out.println(usage);
      System.exit(1);
    }
    long graphNum = Integer.parseInt(args[0]);
    Graph g = makeGraph(graphNum);
    System.out.println(g.nodeCount()+" "+g.edgesToString());
  }

  public static Graph makeGraph(long graphNum) {
    int numBits = 64-Long.numberOfLeadingZeros(graphNum);
    byte nodeCount = 1;
    boolean success = false;
    for (nodeCount = 1; nodeCount<12; nodeCount++) {
      if (nodeCount*(nodeCount-1)/2 >= numBits) {
        success = true;
        break;
      }
    }
    if (!success) {
      throw new RuntimeException("invalid number");
    }
    int nLeadingZeros = nodeCount*(nodeCount-1)/2 - numBits;
    String bitmapString = "";
    for (int i=0; i<nLeadingZeros; i++) {
      bitmapString += "0";
    }
    bitmapString += Long.toBinaryString(graphNum);
    Bitmap bitmap = BitmapFactory.createBitmap(bitmapString);
    return GraphFactory.createGraph(nodeCount, bitmap);
  }
}

@@ -287,19 +287,33 @@
 Number n
+um %5BnodeCount%5D
 %22;%0A
-
     if (
@@ -417,39 +417,126 @@
 m = 
-Integer.parseInt
+Long.parseLong(args%5B0%5D);%0A    Graph g;%0A    if (args.length == 2) %7B%0A      byte nodeCount = Byte.parseByte
 (args%5B
-0
+1
 %5D);%0A    
 Grap
@@ -531,21 +531,76 @@
 %5D);%0A    
+ 
-Graph
+ g = makeGraph(graphNum, nodeCount);%0A    %7D%0A    else %7B%0A     
  g = mak
@@ -613,24 +613,30 @@
 (graphNum);%0A
+    %7D%0A
     System.o
@@ -1077,22 +1077,197 @@
 mber%22);%0A
-
     %7D%0A
+    return makeGraph(graphNum, nodeCount);%0A  %7D%0A    %0A  public static Graph makeGraph(long graphNum, byte nodeCount) %7B%0A    int numBits = 64-Long.numberOfLeadingZeros(graphNum);%0A
     int 

allow node count to be specified