-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
153 lines (150 loc) · 3.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
namespace PixelPrime
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 0 && args[1] == "--test") {
BigInteger prime;
String[] primes;
using (StreamReader sr = new StreamReader("possiblePrimes.txt"))
{
String bigint = sr.ReadToEnd();
primes = bigint.Split('\n');
}
for (int p = 0; p < primes.Length; p++) {
BigInteger.TryParse(primes[p], out prime);
for (int i = 0; i < 128; i++) {
if (RabinMiller.isPrime(prime,1)) {
Console.WriteLine($"Prime {p}, Iteration {i}: Prime");
} else {
Console.WriteLine($"Prime {p}: Not Prime");
}
}
}
} else {
BigInteger perfect;
using (StreamReader sr = new StreamReader("perfectNumber.txt"))
{
String bigint = sr.ReadToEnd();
BigInteger.TryParse(bigint, out perfect);
}
if (perfect%2==0) perfect++;
if (perfect%5==0) perfect += 2;
List<BigInteger> primes = new List<BigInteger>();
Random rand = new Random();
int log = (int)BigInteger.Log10(perfect)+1;
Console.WriteLine("This number has {0} digits",log);
try {
File.Delete("possiblePrimes.txt");
} catch (DirectoryNotFoundException) { }
int solutions = 0;
foreach (BigInteger i in Fluctuate(perfect,max:log/2, repeats:100))
{
if (RabinMiller.isPrime(i,1))
{
if (solutions == 0) File.WriteAllText("possiblePrimes.txt",String.Format("{0}\n",i));
else File.AppendAllText("possiblePrimes.txt",String.Format("{0}\n",i));
Console.WriteLine("Possible prime found");
solutions++;
}
}
}
}
static IEnumerable<BigInteger> Fluctuate(BigInteger number, int max = 5, int repeats = 3)
{
Random random = new Random();
for (int strength = 1; strength <= max; strength++)
{
for (int i = 0; i < repeats; i++)
{
List<int> swapped = new List<int>();
BigInteger fluctuated = number;
for (int j = 0; j < strength; j++) {
int n = random.Next(0,10);
int digit = random.Next(0,(int)(BigInteger.Log10(number)+1));
// Uncomment this to try swapping digits to similar ones.
/*
switch (Digit(number,digit)) {
case 0:
n = 8; break;
case 1:
switch (random.Next(0,2)) {
case 1:
n = 7; break;
case 0:
n = 3; break;
} break;
case 2:
switch (random.Next(0,2)) {
case 1:
n = 5; break;
case 0:
n = 3; break;
} break;
case 3:
switch (random.Next(0,2)) {
case 1:
n = 2; break;
case 0:
n = 1; break;
} break;
case 4:
switch (random.Next(0,2)) {
case 1:
n = 5; break;
case 0:
n = 9; break;
} break;
case 5:
switch (random.Next(0,2)) {
case 1:
n = 4; break;
case 0:
n = 2; break;
} break;
case 6:
switch (random.Next(0,2)) {
case 1:
n = 8; break;
case 0:
n = 9; break;
} break;
case 7:
n = 1; break;
case 8:
switch (random.Next(0,2)) {
case 1:
n = 0; break;
case 0:
n = 6; break;
} break;
case 9:
switch (random.Next(0,2)) {
case 1:
n = 6; break;
case 0:
n = 4; break;
} break;
}
*/
if (!swapped.Contains(digit))
{
int current = Digit(number,digit);
fluctuated += (n-current)*BigInteger.Pow(new BigInteger(10),digit);
swapped.Add(digit);
}
}
yield return fluctuated;
}
}
}
static byte Digit(BigInteger n, int ord) { return (byte)((n / BigInteger.Pow(new BigInteger(10),ord))%10); }
}
}