Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Scanner;
- public class VQCGenerator {
- private static HashMap<Integer, HashMap<Integer, ArrayList<String>>> map = new HashMap<>();
- // ADD PATH HERE
- private static String path = "";
- private static int iMax = 512;
- private static int xMin = -64;
- private static int yMin = 0;
- private static int xMax = 64;
- private static int yMax = 64;
- private static int setSize = 12;
- public static void main(String[] args) {
- createGrid(true, true, false);
- }
- public static void createGrid(boolean parseMap, boolean output, boolean showGraph) {
- for (int i = 0; i < iMax; i++) {
- for (int j = 0; j < i; j++) {
- int a = i - j;
- int b = i + j;
- int c = a * b;
- int d = (int) Math.sqrt(c);
- int e = c - (d*d);
- int f = e - ((2 * d) + 1);
- int n = i - d;
- int x = d - a;
- if (parseMap) {
- createGridImpl(e, x, d, n, a, b, f);
- }
- }
- }
- if (output) {
- outputGrid();
- }
- if (showGraph) {
- //showGraph(xList, yList, "e", "a % (a+b) primes");
- }
- }
- private static void createGridImpl(int e, int n, int d, int x, int a, int b, int f) {
- if (!map.containsKey(e)) {
- map.put(e, new HashMap<Integer, ArrayList<String>>());
- }
- if (!map.get(e).containsKey(n)) {
- map.get(e).put(n, new ArrayList<>());
- }
- if (!map.containsKey(f)) {
- map.put(f, new HashMap<Integer, ArrayList<String>>());
- }
- if (!map.get(f).containsKey(n - 1)) {
- map.get(f).put(n - 1, new ArrayList<String>());
- }
- String formatTemplate = "%1$s:%2$s:%3$s:%4$s:%5$s:%6$s";
- String text = "{" + String.format(formatTemplate, e, n, d, x, a, b) + "}";
- map.get(e).get(n).add(text);
- text = "{" + String.format(formatTemplate, f, n - 1, d + 1, x + 1, a, b) + "}";
- map.get(f).get(n - 1).add(text);
- }
- private static void outputGrid() {
- File f = new File(path);
- try {
- BufferedWriter bw = new BufferedWriter(new FileWriter(f));
- for (int y = 0; y < yMax; y++) {
- for (int z = 0; z < setSize; z++) {
- for (int x = xMin; x < xMax; x++) {
- if ((map.containsKey(x)) && (map.get(x).containsKey(y)) && (map.get(x).get(y).size() > z)) {
- bw.write(map.get(x).get(y).get(z) + ",");
- } else {
- bw.write(",");
- }
- }
- bw.write("\n");
- }
- }
- bw.close();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment