Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement