Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

50
LINES

< > BotCompany Repo | #1035202 // FindAllLSFRTriplets

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (8685L/49K).

srecord noeq FindAllLSFRTriplets(int bits) {
  // Try triplets that are actually just pairs or even a single xorshift
  // (these will be indicated by a, b or c being 0)
  settable bool tryDegenerateTriplets = true;
  
  event testingTriplet(int[] triplet, CheckLSFRTriplet checker);
  event tripletFound(int[] triplet);
  event tripletRejected(int[] triplet, CheckLSFRTriplet checker);
  
  ItIt<L<Int>> iterator;
  long steps;
  
  int cycleLength() { ret (1 << bits)-1; }
  
  void init {
    iterator if null = outerProduct(repF(3,
      -> virtualCountList(tryDegenerateTriplets ? 0 : 1, bits)));
  }
  
  long expectedSteps() {
    long n = tryDegenerateTriplets ? bits : bits-1;
    ret n*n*n;
  }
  
  // return next working triplet or null if end of search
  int[] next() {
    init();
    
    for (L<Int> t : iterator) {
      int[] triplet = new int[] {t.get(0), t.get(1), t.get(2)};
      ++steps;
      CheckLSFRTriplet checker = new(bits, triplet);
      testingTriplet(triplet, checker);
      if (checker!) {
        tripletFound(triplet);
        ret triplet;
      } else
        tripletRejected(triplet, checker);
    }
    null;
  }

  L<int[]> getAll() {
    new L<int[]> workingTriplets;
    int[] triplet;
    while ((triplet = next()) != null)
      workingTriplets.add(triplet);
    ret workingTriplets;
  }
}

Author comment

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: 147 / 285
Version history: 16 change(s)
Referenced in: [show references]