Guest User

TheEnd.cs

a guest
Dec 9th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Drawing;
  5.  
  6. namespace IntegerFactorisation
  7. {
  8.     public class TheEnd
  9.     {
  10.         public static string path = "";//PUT YOUR FILE PATH HERE
  11.  
  12.         public static Dictionary<int, Dictionary<int, List<string>>> theend = new Dictionary<int, Dictionary<int, List<string>>>();
  13.  
  14.         public static void CreateTheEnd(int i_max = 1024, int x_min = -512, int y_min = 0, int x_max = 512, int y_max = 512)
  15.         {
  16.             int higheste = 0;
  17.             int highestn = 0;
  18.             int highestd = 0;
  19.             int highestx = 0;
  20.             int highesta = 0;
  21.             int highestb = 0;
  22.  
  23.             //int[][] test = FromCgetN(39);
  24.  
  25.             for (int i = 0; i < i_max; i++)
  26.             {
  27.                 for (int j = 0; j < i; j++)
  28.                 {
  29.                     int a = i - j;
  30.  
  31.                     int b = i + j;
  32.  
  33.                     int c = a * b;
  34.  
  35.                     bool odd = c % 2 == 1;
  36.  
  37.                     int d = (int)Math.Sqrt(c);
  38.  
  39.                     int e = c - (d * d);
  40.  
  41.                     int f = e - ((2 * d) + 1);
  42.  
  43.                     int n = i - d;
  44.  
  45.                     int x = d - a;
  46.  
  47.                     if (!theend.ContainsKey(e)) theend[e] = new Dictionary<int, List<string>>();
  48.  
  49.                     if (!theend[e].ContainsKey(n))
  50.                     {
  51.                         theend[e][n] = new List<string>();
  52.                     }
  53.  
  54.                     if (!theend.ContainsKey(f)) theend[f] = new Dictionary<int, List<string>>();
  55.  
  56.                     if (!theend[f].ContainsKey(n - 1)) theend[f][n - 1] = new List<string>();
  57.  
  58.                     string text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", e, n, d, x, a, b) + "}";
  59.  
  60.                     theend[e][n].Add(text);
  61.  
  62.                     text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", f, n - 1, d + 1, x + 1, a, b) + "}";
  63.  
  64.                     theend[f][n - 1].Add(text);
  65.  
  66.                     if (e > higheste) higheste = e;
  67.                     if (n > highestn) highestn = n;
  68.                     if (d > highestd) highestd = d;
  69.                     if (x > highestx) highestx = x;
  70.                     if (a > highesta) highesta = a;
  71.                     if (b > highestb) highestb = b;
  72.                 }
  73.             }
  74.             Console.WriteLine("i_max: " + i_max);
  75.             Console.WriteLine("x_min: " + x_min);
  76.             Console.WriteLine("x_max: " + x_max);
  77.             Console.WriteLine("y_min: " + y_min);
  78.             Console.WriteLine("y_max: " + y_max);
  79.             Console.WriteLine("Highest e: " + higheste);
  80.             Console.WriteLine("Highest n: " + highestn);
  81.             Console.WriteLine("Highest d: " + highestd);
  82.             Console.WriteLine("Highest x: " + highestx);
  83.             Console.WriteLine("Highest a: " + highesta);
  84.             Console.WriteLine("Highest b: " + highestb);
  85.  
  86.         }
  87.  
  88.         public static void Output(int i_max = 1024, int x_min = -512, int y_min = 0, int x_max = 512, int y_max = 512, int set_size = 12)
  89.         {
  90.             TextWriter tw = File.CreateText(path + "output.csv");
  91.  
  92.             Bitmap bmp = new Bitmap(x_max - x_min, y_max - y_min);
  93.             Bitmap bmp_even = new Bitmap(x_max - x_min, y_max - y_min);
  94.             Bitmap bmp_odd = new Bitmap(x_max - x_min, y_max - y_min);
  95.  
  96.             using (Graphics g = Graphics.FromImage(bmp))
  97.             {
  98.                 g.FillRectangle(Brushes.Black, 0, 0, bmp.Width, bmp.Height);
  99.             }
  100.             using (Graphics g = Graphics.FromImage(bmp_even))
  101.             {
  102.                 g.FillRectangle(Brushes.Black, 0, 0, bmp_even.Width, bmp_even.Height);
  103.             }
  104.             using (Graphics g = Graphics.FromImage(bmp_odd))
  105.             {
  106.                 g.FillRectangle(Brushes.Black, 0, 0, bmp_odd.Width, bmp_odd.Height);
  107.             }
  108.  
  109.             for (int y = 0; y < y_max; y++)
  110.             {
  111.                 for (int z = 0; z < set_size; z++)
  112.                 {
  113.                     for (int x = x_min; x < x_max; x++)
  114.                     {
  115.                         if (theend.ContainsKey(x) && theend[x].ContainsKey(y) && theend[x][y].Count > z)
  116.                         {
  117.                             tw.Write(theend[x][y][z] + ",");
  118.  
  119.                             String[] values = theend[x][y][z].Split(':');
  120.  
  121.                             int e = Int32.Parse(values[0].Split('{')[1]);
  122.                             int n = Int32.Parse(values[1]);
  123.                             int d = Int32.Parse(values[2]);
  124.                             int xx = Int32.Parse(values[3]);
  125.                             int a = Int32.Parse(values[4]);
  126.                             int b = Int32.Parse(values[5].Split('}')[0]);
  127.                             int c = a * b;
  128.  
  129.                             int red = xx * 255 / (i_max / 2);
  130.                             int green = a * 255 / i_max;
  131.                             int blue = b * 255 / (i_max * 2);
  132.  
  133.                             bmp.SetPixel(x + x_max, y, Color.FromArgb(255, red, green, blue));
  134.  
  135.                             if (e % 2 == 0)
  136.                             {
  137.                                 bmp_even.SetPixel(x + x_max, y, Color.FromArgb(255, red, green, blue));
  138.                             }
  139.                             else
  140.                             {
  141.                                 bmp_odd.SetPixel(x + x_max, y, Color.FromArgb(255, red, green, blue));
  142.                             }
  143.                         }
  144.                         else
  145.                         {
  146.                             tw.Write(",");
  147.                         }
  148.                     }
  149.                     tw.WriteLine("");
  150.                 }
  151.             }
  152.             tw.Close();
  153.  
  154.             String format = "output_imax_" + i_max + "_xmin_" + x_min + "_xmax_" + x_max + "_ymax_" + y_max;
  155.  
  156.             bmp.Save(path + format + "_both.png");
  157.             bmp_even.Save(path + format + "_even-e.png");
  158.             bmp_odd.Save(path + format + "_odd-e.png");
  159.         }
  160.  
  161.  
  162.  
  163.         // !LAbIRp9cT.
  164.  
  165.         public static int[][] FromCgetN(int c)
  166.         {
  167.             //#(e,n,d,x,a,b)
  168.             int[] cellC = CreateForC(c);
  169.             List<int> factors1 = new List<int>();
  170.             List<int> factors2 = new List<int>();
  171.  
  172.             while (c > 0)
  173.             {
  174.                 if (c % 2 != 0)
  175.                 {
  176.                     int[] cell = CreateForF(cellC);
  177.                     factors1.Add(cell[0]);
  178.                 }
  179.                 else
  180.                 {
  181.                     int[] cell = CreateForAB(cellC[4], cellC[5]);
  182.                     factors2.Add(cell[0]);
  183.                 }
  184.                 c = c >> 1;
  185.             }
  186.             return new int[][] { factors1.ToArray(), factors2.ToArray() };
  187.         }
  188.  
  189.         private static int[] CreateForC(int c)
  190.         {
  191.             int d = (int)Math.Sqrt(c);
  192.             int e = c - (d * d);
  193.             int a = 1;
  194.             int b = c;
  195.             int x = d - a;
  196.             int n = ((x * x) + e / (2 * a));
  197.  
  198.             return new int[] { e, n, d, x, a, b };
  199.         }
  200.  
  201.         private static int[] CreateForF(int[] rec)
  202.         {
  203.             int e = rec[0] - ((2 * rec[2]) + 1);
  204.             int n = rec[1] - 1;
  205.             int d = rec[2] + 1;
  206.             int x = rec[3] + 1;
  207.             int a = rec[4];
  208.             int b = rec[5];
  209.  
  210.             return new int[] { e, n, d, x, a, b };
  211.         }
  212.  
  213.         private static int[] CreateForAB(int a, int b)
  214.         {
  215.             int d;
  216.             int c = a * b;
  217.  
  218.             if (c < 0)
  219.                 d = (int)Math.Sqrt(-c);
  220.             else
  221.                 d = (int)Math.Sqrt(c);
  222.  
  223.             int e = c - (d * d);
  224.             int x = d - a;
  225.             int n = ((x * x) + e) / (2 * a);
  226.  
  227.             return new int[] { e, n, d, x, a, b };
  228.         }
  229.     }
  230. }
Add Comment
Please, Sign In to add comment