Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,33 @@
import java.util.Arrays;
import java.util.stream.IntStream;
public class PerfectShuffle {
public static void main(String[] args) {
int[] sizes = {8, 24, 52, 100, 1020, 1024, 10_000};
for (int size : sizes)
System.out.printf("%5d : %5d%n", size, perfectShuffle(size));
}
static int perfectShuffle(int size) {
if (size % 2 != 0)
throw new IllegalArgumentException("size must be even");
int half = size / 2;
int[] a = IntStream.range(0, size).toArray();
int[] original = a.clone();
int[] aa = new int[size];
for (int count = 1; true; count++) {
System.arraycopy(a, 0, aa, 0, size);
for (int i = 0; i < half; i++) {
a[2 * i] = aa[i];
a[2 * i + 1] = aa[i + half];
}
if (Arrays.equals(a, original))
return count;
}
}
}