Advertisement
defango

GridCreate

Dec 4th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. //To create the grid, attached is a c# file.
  2. //There is a method that constructs the grid.
  3. //There is an output method.
  4. //Please specify a path to save output to.
  5. //Next, we will look at some properties of the grid and also examine the all important first row.
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. namespace IntegerFactorisation
  11. {
  12.     public class TheEnd
  13.     {
  14.         public static string path = "";//PUT YOUR FILE PATH HERE
  15.         public static Dictionary<int, Dictionary<int, List<string>>> theend = new Dictionary<int, Dictionary<int, List<string>>>();
  16.        
  17.         public static void CreateTheEnd(int i_max = 512, int x_min = 0, int y_min = 0, int x_max = 64, int y_max = 64)
  18.         {
  19.             for (int i = 0; i < i_max; i++)
  20.             {
  21.                 for (int j = 0; j < i; j++)
  22.                 {
  23.                     int a = i - j;
  24.                     int b = i + j;
  25.                     int c = a * b;
  26.                     bool odd = c % 2 == 1;
  27.                     int d = (int)Math.Sqrt(c);
  28.                     int e = c - (d * d);
  29.                     int f = e - ((2 * d) + 1);
  30.                     int n = i - d;
  31.                     int x = d - a;
  32.                     if (!theend.ContainsKey(e)) theend[e] = new Dictionary<int, List<string>>();
  33.                     if (!theend[e].ContainsKey(n))
  34.                     {
  35.                         theend[e][n] = new List<string>();
  36.                        
  37.                     }
  38.                     if (!theend.ContainsKey(f)) theend[f] = new Dictionary<int, List<string>>();
  39.                     if (!theend[f].ContainsKey(n - 1)) theend[f][n - 1] = new List<string>();
  40.                     string text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", e, n, d, x, a, b) + "}";
  41.                     theend[e][n].Add(text);
  42.                     text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", f, n - 1, d + 1, x + 1, a, b) + "}";
  43.                     theend[f][n - 1].Add(text);
  44.                 }
  45.             }
  46.         }
  47.         public static void Output(int i_max = 256, int x_min = -64, int y_min = 0, int x_max = 64, int y_max = 64, int set_size = 12)
  48.         {
  49.             TextWriter tw = File.CreateText(path + "output.csv");
  50.             for (int y = 0; y < y_max; y++)
  51.             {
  52.                 for (int z = 0; z < set_size; z++)
  53.                 {
  54.                     for (int x = x_min; x < x_max; x++)
  55.                     {
  56.                         if (theend.ContainsKey(x) && theend[x].ContainsKey(y) && theend[x][y].Count > z)
  57.                         {
  58.                             tw.Write(theend[x][y][z] + ",");
  59.                         }
  60.                         else
  61.                         {
  62.                             tw.Write(",");
  63.                         }
  64.                     }
  65.                     tw.WriteLine("");
  66.                 }
  67.             }
  68.             tw.Close();
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement