defango

MUSTACHE

Apr 9th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedWriter;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.Scanner;
  8.  
  9. public class VQCGenerator {
  10.     private static HashMap<Integer, HashMap<Integer, ArrayList<String>>> map = new HashMap<>();
  11.  
  12.     // ADD PATH HERE
  13.     private static String path = "";
  14.  
  15.     private static int iMax = 512;
  16.     private static int xMin = -64;
  17.     private static int yMin = 0;
  18.     private static int xMax = 64;
  19.     private static int yMax = 64;
  20.     private static int setSize = 12;
  21.  
  22.     public static void main(String[] args) {
  23.         createGrid(true, true, false);
  24.     }
  25.  
  26.     public static void createGrid(boolean parseMap, boolean output, boolean showGraph) {
  27.  
  28.         for (int i = 0; i < iMax; i++) {
  29.             for (int j = 0; j < i; j++) {
  30.  
  31.                 int a = i - j;
  32.                 int b = i + j;
  33.                 int c = a * b;
  34.                 int d = (int) Math.sqrt(c);
  35.                 int e = c - (d*d);
  36.                 int f = e - ((2 * d) + 1);
  37.                 int n = i - d;
  38.                 int x = d - a;
  39.  
  40.                 if (parseMap) {
  41.                    createGridImpl(e, x, d, n, a, b, f);
  42.                 }
  43.             }
  44.         }
  45.  
  46.         if (output) {
  47.             outputGrid();
  48.         }
  49.  
  50.         if (showGraph) {
  51.             //showGraph(xList, yList, "e", "a % (a+b) primes");
  52.         }
  53.     }
  54.  
  55.     private static void createGridImpl(int e, int n, int d, int x, int a, int b, int f) {
  56.         if (!map.containsKey(e)) {
  57.             map.put(e, new HashMap<Integer, ArrayList<String>>());
  58.         }
  59.  
  60.         if (!map.get(e).containsKey(n)) {
  61.             map.get(e).put(n, new ArrayList<>());
  62.         }
  63.  
  64.         if (!map.containsKey(f)) {
  65.             map.put(f, new HashMap<Integer, ArrayList<String>>());
  66.         }
  67.  
  68.         if (!map.get(f).containsKey(n - 1)) {
  69.             map.get(f).put(n - 1, new ArrayList<String>());
  70.         }
  71.  
  72.         String formatTemplate = "%1$s:%2$s:%3$s:%4$s:%5$s:%6$s";
  73.  
  74.         String text = "{" + String.format(formatTemplate, e, n, d, x, a, b) + "}";
  75.         map.get(e).get(n).add(text);
  76.  
  77.         text = "{" + String.format(formatTemplate, f, n - 1, d + 1, x + 1, a, b) + "}";
  78.         map.get(f).get(n - 1).add(text);
  79.     }
  80.  
  81.     private static void outputGrid() {
  82.         File f = new File(path);
  83.  
  84.         try {
  85.             BufferedWriter bw = new BufferedWriter(new FileWriter(f));
  86.  
  87.             for (int y = 0; y < yMax; y++) {
  88.                 for (int z = 0; z < setSize; z++) {
  89.                     for (int x = xMin; x < xMax; x++) {
  90.  
  91.                         if ((map.containsKey(x)) && (map.get(x).containsKey(y)) && (map.get(x).get(y).size() > z)) {
  92.                             bw.write(map.get(x).get(y).get(z) + ",");
  93.                         } else {
  94.                             bw.write(",");
  95.                         }
  96.  
  97.                     }
  98.                     bw.write("\n");
  99.                 }
  100.             }
  101.  
  102.             bw.close();
  103.         } catch (IOException ioe) {
  104.             ioe.printStackTrace();
  105.         }
  106.     }
  107. }
Add Comment
Please, Sign In to add comment