Libraryless. Click here for Pure Java version (8685L/49K).
1 | srecord noeq FindAllLSFRTriplets(int bits) { |
2 | // Try triplets that are actually just pairs or even a single xorshift |
3 | // (these will be indicated by a, b or c being 0) |
4 | settable bool tryDegenerateTriplets = true; |
5 | |
6 | event testingTriplet(int[] triplet, CheckLSFRTriplet checker); |
7 | event tripletFound(int[] triplet); |
8 | event tripletRejected(int[] triplet, CheckLSFRTriplet checker); |
9 | |
10 | ItIt<L<Int>> iterator; |
11 | long steps; |
12 | |
13 | int cycleLength() { ret (1 << bits)-1; } |
14 | |
15 | void init { |
16 | iterator if null = outerProduct(repF(3, |
17 | -> virtualCountList(tryDegenerateTriplets ? 0 : 1, bits))); |
18 | } |
19 | |
20 | long expectedSteps() { |
21 | long n = tryDegenerateTriplets ? bits : bits-1; |
22 | ret n*n*n; |
23 | } |
24 | |
25 | // return next working triplet or null if end of search |
26 | int[] next() { |
27 | init(); |
28 | |
29 | for (L<Int> t : iterator) { |
30 | int[] triplet = new int[] {t.get(0), t.get(1), t.get(2)}; |
31 | ++steps; |
32 | CheckLSFRTriplet checker = new(bits, triplet); |
33 | testingTriplet(triplet, checker); |
34 | if (checker!) { |
35 | tripletFound(triplet); |
36 | ret triplet; |
37 | } else |
38 | tripletRejected(triplet, checker); |
39 | } |
40 | null; |
41 | } |
42 | |
43 | L<int[]> getAll() { |
44 | new L<int[]> workingTriplets; |
45 | int[] triplet; |
46 | while ((triplet = next()) != null) |
47 | workingTriplets.add(triplet); |
48 | ret workingTriplets; |
49 | } |
50 | } |
Began life as a copy of #1035201
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035202 |
Snippet name: | FindAllLSFRTriplets |
Eternal ID of this version: | #1035202/17 |
Text MD5: | 754c43bc5bd47c7e901871078353e38c |
Transpilation MD5: | 996611d36f3942b1599d750db8e830ca |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-04-15 03:10:09 |
Source code size: | 1384 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 148 / 286 |
Version history: | 16 change(s) |
Referenced in: | [show references] |