This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
forked from KrasiF/sorting-algos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
placeholder dumps.txt
430 lines (391 loc) · 21 KB
/
placeholder dumps.txt
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
case 0: //reset
int n = arr.Length - 1;
double c = 2 * Math.PI / n;
arr = new int[(int)ArraySize.Value];
for (int i = 0; i < arr.Length; i++)
{
arr[i] = i + 1;
selectedArr = new int[] { i };
}
AddHistorySnap();
switch (distribcomboBox.SelectedIndex)
{
//case 0: linear, default
case 1: //few unique
int l = 0, r, t = Math.Min(arr.Length, 8);
for (int i = 0; i < t; i++)
{
if (random.NextDouble() < 0.5)
{
l++;
}
selectedArr = new int[] { i };
}
r = arr.Length - (t - l);
for (int i = 0; i < l; i++)
{
arr[i] = (int)(arr.Length * 0.25);
selectedArr = new int[] { i };
}
for (int i = 0; i < r; i++)
{
arr[i] = arr.Length / 2;
selectedArr = new int[] { i };
}
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(arr.Length * 0.75);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 2: //no unique
int val = arr.Length / 2;
for (int i = 0; i < arr.Length; i++)
{
arr[i] = val;
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 3: //noise
for (int i = 0; i < arr.Length; i++)
{
arr[i] = random.Next(arr.Length);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 4: //quadratic curve
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(Math.Pow(i, 2) / arr.Length);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 5: //square root curve
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(Math.Sqrt(i) * Math.Sqrt(arr.Length));
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 6: //cubic curve
double mid = (arr.Length - 1) / 2d;
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)((Math.Pow(i - mid, 3) / Math.Pow(mid, 3 - 1)) + mid);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 7: //quintic curve
double midd = (arr.Length - 1) / 2d;
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)((Math.Pow(i - midd, 5) / Math.Pow(midd, 5 - 1)) + midd);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 8: //cube root curve
double h = arr.Length / 2d;
for (int i = 0; i < arr.Length; i++)
{
double vall = i / h - 1,
root = vall < 0 ? -Math.Pow(-vall, 1d / 3) : Math.Pow(vall, 1d / 3);
arr[i] = (int)(h * (root + 1));
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 9: //fifth root curve
double hh = arr.Length / 2d;
for (int i = 0; i < arr.Length; i++)
{
double vall = i / hh - 1,
root = vall < 0 ? -Math.Pow(-vall, 1d / 5) : Math.Pow(vall, 1d / 5);
arr[i] = (int)(hh * (root + 1));
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 10: //sine
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(n * (Math.Sin(c * i) + 1) / 2);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 11: //cosine
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(n * (Math.Cos(c * i) + 1) / 2);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 12: //tangent
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(n * (Math.Tan(c * i) + 1) / 2);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 13: //perlin noise
int[] perlinNoise = new int[arr.Length];
float step = 1f / arr.Length;
float randomStart = random.Next(arr.Length);
int octave = (int)(Math.Log(arr.Length) / Math.Log(2));
for (int i = 0; i < arr.Length; i++)
{
int value = (int)(PerlinNoise.ReturnFracBrownNoise(randomStart, octave) * arr.Length);
perlinNoise[i] = value;
randomStart += step;
selectedArr = new int[] { i };
}
int minimum = int.MaxValue;
for (int i = 0; i < arr.Length; i++)
{
if (perlinNoise[i] < minimum)
{
minimum = perlinNoise[i];
}
selectedArr = new int[] { i };
}
minimum = Math.Abs(minimum);
for (int i = 0; i < arr.Length; i++)
{
perlinNoise[i] += minimum;
selectedArr = new int[] { i };
}
double maximum = double.MinValue;
for (int i = 0; i < arr.Length; i++)
{
if (perlinNoise[i] > maximum)
{
maximum = perlinNoise[i];
}
selectedArr = new int[] { i };
}
double scale = arr.Length / maximum;
if (scale is < 1.0 or > 1.8)
{
for (int i = 0; i < arr.Length; i++)
{
perlinNoise[i] = (int)(perlinNoise[i] * scale);
selectedArr = new int[] { i };
}
}
for (int i = 0; i < arr.Length; i++)
{
arr[i] = Math.Min(perlinNoise[i], arr.Length - 1);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 14: //perlin noise curve
for (int i = 0; i < arr.Length; i++)
{
int value = 0 - (int)(PerlinNoise.ReturnNoise((float)i / arr.Length) * arr.Length);
arr[i] = Math.Min(value, arr.Length - 1);
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 15: //bell curve
double stepp = 8d / arr.Length;
double position = -4;
int constant = 1264;
double factor = arr.Length / 512d;
for (int i = 0; i < arr.Length; i++)
{
double square = Math.Pow(position, 2);
double negativeSquare = 0 - square;
double halfNegSquare = negativeSquare / 2d;
double numerator = constant * factor * Math.Pow(Math.E, halfNegSquare);
double doublePi = 2 * Math.PI;
double denominator = Math.Sqrt(doublePi);
arr[i] = (int)(numerator / denominator);
position += stepp;
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 16: //ruler
int steppp = Math.Max(1, arr.Length / 256);
int floorLog2 = (int)(Math.Log(arr.Length / steppp) / Math.Log(2));
int lowest;
for (lowest = steppp; 2 * lowest <= arr.Length / 4; lowest *= 2) ;
bool[] digits = new bool[floorLog2 + 2];
int ii, jj;
for (ii = 0; ii + steppp <= arr.Length; ii += steppp)
{
for (jj = 0; digits[jj]; jj++) ;
digits[jj] = true;
for (int k = 0; k < steppp; k++)
{
int value = arr.Length / 2 - Math.Min((1 << jj) * steppp, lowest);
arr[ii + k] = value;
}
for (int k = 0; k < jj; k++) digits[k] = false;
selectedArr = new int[] { ii };
}
for (jj = 0; digits[jj]; jj++) ;
digits[jj] = true;
while (ii < arr.Length)
{
int value = Math.Max(arr.Length / 2 - ((1 << jj) * steppp), arr.Length / 4);
arr[ii++] = value;
selectedArr = new int[] { ii };
}
AddHistorySnap();
break;
case 17: //blancmange curve
int floorLog22 = (int)(Math.Log(arr.Length) / Math.Log(2));
for (int i = 0; i < arr.Length; i++)
{
int value = (int)(arr.Length * curveSum(floorLog22, (double)i / arr.Length));
arr[i] = value;
selectedArr = new int[] { i };
}
double curveSum(int n, double x)
{
double sum = 0;
while (n >= 0)
{
sum += curve(n--, x);
}
return sum;
}
double curve(int n, double x)
{
return triangleWave((1 << n) * x) / (1 << n);
}
double triangleWave(double x)
{
return Math.Abs(x - (int)(x + 0.5));
}
AddHistorySnap();
break;
case 18: //cantor function
cantor(arr, 0, arr.Length, 0, arr.Length - 1);
void cantor(int[] array, int a, int b, int min, int max)
{
if (b - a < 1 || max == min)
{
return;
}
int mid = (min + max) / 2;
if (b - a == 1)
{
array[a] = mid;
return;
}
int t1 = (a + a + b) / 3, t2 = (a + b + b + 2) / 3;
for (int i = t1; i < t2; i++)
{
array[i] = mid;
selectedArr = new int[] { i };
}
cantor(array, a, t1, min, mid);
cantor(array, t2, b, mid + 1, max);
}
AddHistorySnap();
break;
case 19: //sum of divisors
int[] nn = new int[arr.Length];
nn[0] = 0;
nn[1] = 1;
double max = 1;
for (int i = 2; i < arr.Length; i++)
{
nn[i] = sumDivisors(i);
if (nn[i] > max) max = nn[i];
selectedArr = new int[] { i };
}
double scalee = Math.Min((arr.Length - 1) / max, 1);
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(nn[i] * scalee);
selectedArr = new int[] { i };
}
int sumDivisors(int n)
{
int sum = n + 1;
for (int i = 2; i <= (int)Math.Sqrt(n); i++)
{
if (n % i == 0)
{
if (i == n / i)
{
sum += i;
}
else
{
sum += i + n / i;
}
}
selectedArr = new int[] { i };
}
return sum;
}
AddHistorySnap();
break;
case 20: //oeis fly straight
int[] fsd = new int[arr.Length];
double maxx;
maxx = fsd[0] = fsd[1] = 1;
for (int i = 2; i < arr.Length; i++)
{
int g = gcd(fsd[i - 1], i);
fsd[i] = fsd[i - 1] / g + (g == 1 ? i + 1 : 0);
if (fsd[i] > maxx)
{
maxx = fsd[i];
}
selectedArr = new int[] { i };
}
double scalew = Math.Min((arr.Length - 1) / maxx, 1);
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (int)(fsd[i] * scalew);
selectedArr = new int[] { i };
}
int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
AddHistorySnap();
break;
case 21: //decreasing random
for (int i = 0; i < arr.Length; i++)
{
int rr = random.Next(arr.Length - i) + i;
arr[i] = rr;
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
case 22: //modulo function
for (int i = 0; i < arr.Length; i++)
{
arr[i] = 2 * (arr.Length % (i + 1));
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
default: //case 0
for (int i = 0; i < arr.Length; i++)
{
arr[i] = i + 1;
selectedArr = new int[] { i };
}
AddHistorySnap();
break;
}
break;