Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Drawing;
- namespace IntegerFactorisation
- {
- public class TheEnd
- {
- public static string path = "";//PUT YOUR FILE PATH HERE
- public static Dictionary<int, Dictionary<int, List<string>>> theend = new Dictionary<int, Dictionary<int, List<string>>>();
- public static void CreateTheEnd(int i_max = 1024, int x_min = -512, int y_min = 0, int x_max = 512, int y_max = 512)
- {
- int higheste = 0;
- int highestn = 0;
- int highestd = 0;
- int highestx = 0;
- int highesta = 0;
- int highestb = 0;
- //int[][] test = FromCgetN(39);
- for (int i = 0; i < i_max; i++)
- {
- for (int j = 0; j < i; j++)
- {
- int a = i - j;
- int b = i + j;
- int c = a * b;
- bool odd = c % 2 == 1;
- 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 (!theend.ContainsKey(e)) theend[e] = new Dictionary<int, List<string>>();
- if (!theend[e].ContainsKey(n))
- {
- theend[e][n] = new List<string>();
- }
- if (!theend.ContainsKey(f)) theend[f] = new Dictionary<int, List<string>>();
- if (!theend[f].ContainsKey(n - 1)) theend[f][n - 1] = new List<string>();
- string text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", e, n, d, x, a, b) + "}";
- theend[e][n].Add(text);
- text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", f, n - 1, d + 1, x + 1, a, b) + "}";
- theend[f][n - 1].Add(text);
- if (e > higheste) higheste = e;
- if (n > highestn) highestn = n;
- if (d > highestd) highestd = d;
- if (x > highestx) highestx = x;
- if (a > highesta) highesta = a;
- if (b > highestb) highestb = b;
- }
- }
- Console.WriteLine("i_max: " + i_max);
- Console.WriteLine("x_min: " + x_min);
- Console.WriteLine("x_max: " + x_max);
- Console.WriteLine("y_min: " + y_min);
- Console.WriteLine("y_max: " + y_max);
- Console.WriteLine("Highest e: " + higheste);
- Console.WriteLine("Highest n: " + highestn);
- Console.WriteLine("Highest d: " + highestd);
- Console.WriteLine("Highest x: " + highestx);
- Console.WriteLine("Highest a: " + highesta);
- Console.WriteLine("Highest b: " + highestb);
- }
- 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)
- {
- TextWriter tw = File.CreateText(path + "output.csv");
- Bitmap bmp = new Bitmap(x_max - x_min, y_max - y_min);
- Bitmap bmp_even = new Bitmap(x_max - x_min, y_max - y_min);
- Bitmap bmp_odd = new Bitmap(x_max - x_min, y_max - y_min);
- using (Graphics g = Graphics.FromImage(bmp))
- {
- g.FillRectangle(Brushes.Black, 0, 0, bmp.Width, bmp.Height);
- }
- using (Graphics g = Graphics.FromImage(bmp_even))
- {
- g.FillRectangle(Brushes.Black, 0, 0, bmp_even.Width, bmp_even.Height);
- }
- using (Graphics g = Graphics.FromImage(bmp_odd))
- {
- g.FillRectangle(Brushes.Black, 0, 0, bmp_odd.Width, bmp_odd.Height);
- }
- for (int y = 0; y < y_max; y++)
- {
- for (int z = 0; z < set_size; z++)
- {
- for (int x = x_min; x < x_max; x++)
- {
- if (theend.ContainsKey(x) && theend[x].ContainsKey(y) && theend[x][y].Count > z)
- {
- tw.Write(theend[x][y][z] + ",");
- String[] values = theend[x][y][z].Split(':');
- int e = Int32.Parse(values[0].Split('{')[1]);
- int n = Int32.Parse(values[1]);
- int d = Int32.Parse(values[2]);
- int xx = Int32.Parse(values[3]);
- int a = Int32.Parse(values[4]);
- int b = Int32.Parse(values[5].Split('}')[0]);
- int c = a * b;
- int red = xx * 255 / (i_max / 2);
- int green = a * 255 / i_max;
- int blue = b * 255 / (i_max * 2);
- bmp.SetPixel(x + x_max, y, Color.FromArgb(255, red, green, blue));
- if (e % 2 == 0)
- {
- bmp_even.SetPixel(x + x_max, y, Color.FromArgb(255, red, green, blue));
- }
- else
- {
- bmp_odd.SetPixel(x + x_max, y, Color.FromArgb(255, red, green, blue));
- }
- }
- else
- {
- tw.Write(",");
- }
- }
- tw.WriteLine("");
- }
- }
- tw.Close();
- String format = "output_imax_" + i_max + "_xmin_" + x_min + "_xmax_" + x_max + "_ymax_" + y_max;
- bmp.Save(path + format + "_both.png");
- bmp_even.Save(path + format + "_even-e.png");
- bmp_odd.Save(path + format + "_odd-e.png");
- }
- // !LAbIRp9cT.
- public static int[][] FromCgetN(int c)
- {
- //#(e,n,d,x,a,b)
- int[] cellC = CreateForC(c);
- List<int> factors1 = new List<int>();
- List<int> factors2 = new List<int>();
- while (c > 0)
- {
- if (c % 2 != 0)
- {
- int[] cell = CreateForF(cellC);
- factors1.Add(cell[0]);
- }
- else
- {
- int[] cell = CreateForAB(cellC[4], cellC[5]);
- factors2.Add(cell[0]);
- }
- c = c >> 1;
- }
- return new int[][] { factors1.ToArray(), factors2.ToArray() };
- }
- private static int[] CreateForC(int c)
- {
- int d = (int)Math.Sqrt(c);
- int e = c - (d * d);
- int a = 1;
- int b = c;
- int x = d - a;
- int n = ((x * x) + e / (2 * a));
- return new int[] { e, n, d, x, a, b };
- }
- private static int[] CreateForF(int[] rec)
- {
- int e = rec[0] - ((2 * rec[2]) + 1);
- int n = rec[1] - 1;
- int d = rec[2] + 1;
- int x = rec[3] + 1;
- int a = rec[4];
- int b = rec[5];
- return new int[] { e, n, d, x, a, b };
- }
- private static int[] CreateForAB(int a, int b)
- {
- int d;
- int c = a * b;
- if (c < 0)
- d = (int)Math.Sqrt(-c);
- else
- d = (int)Math.Sqrt(c);
- int e = c - (d * d);
- int x = d - a;
- int n = ((x * x) + e) / (2 * a);
- return new int[] { e, n, d, x, a, b };
- }
- }
- }
Add Comment
Please, Sign In to add comment