daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main() {
  2.   var result = integerToCode(BigInt.parse('9348079487942378923479823497823523852323552352235452342434434297834'), 52);
  3.   var arr = List.generate(52, (ind) => ind);
  4.   print(codeToPermutation(arr, result));
  5. }
  6.  
  7. BigInt fact(int n) {
  8.   if (n < 0) {
  9.     throw new Exception('Argument less than 0');
  10.   }
  11.   BigInt param = BigInt.from(n);
  12.   BigInt res = BigInt.from(1);
  13.   BigInt incre = BigInt.from(1);
  14.   for (BigInt i = BigInt.from(1); i <= param;) {
  15.     res *= i;
  16.     i += incre;
  17.   }
  18.   return res;
  19. }
  20.  
  21. List<int> integerToCode(BigInt integer, permSize) {
  22.   if (permSize <= 1) {
  23.     return [0];
  24.   }
  25.   BigInt multiplier = fact(permSize - 1);
  26.   var digit = (integer ~/ multiplier);
  27.   return [digit.toInt()]
  28.     ..addAll(integerToCode((integer % multiplier), permSize - 1));
  29. }
  30.  
  31. List<int> codeToPermutation(List<int> elements, List<int> code) {
  32.   return code.map((index) {
  33.     var elem = elements[index];
  34.     elements.removeAt(index);
  35.     return elem;
  36.   }).toList();
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top