fork download
  1.  
  2. function shuffleArray(array) {
  3. for (let i = array.length - 1; i > 0; i--) {
  4. const j = Math.floor(Math.random() * (i + 1));
  5. [array[i], array[j]] = [array[j], array[i]]; // Swap elements
  6. }
  7. }
  8.  
  9. function merge(arr1, arr2) {
  10. const merged = [];
  11. let i = 0;
  12. let j = 0;
  13.  
  14. while (i < arr1.length || j < arr2.length) {
  15. if (Math.random() < 0.5 && i < arr1.length) {
  16. merged.push(arr1[i]);
  17. i++;
  18. } else if (j < arr2.length) {
  19. merged.push(arr2[j]);
  20. j++;
  21. }
  22. }
  23.  
  24. return merged;
  25. }
  26.  
  27. function f(n) {
  28. const zoos = [0, 1, 10];
  29. const zoo = [];
  30. const result = [];
  31. for (let i = 0; i < 12; i++) {
  32. if ((1 << i) & n) {
  33. if (zoos.includes(i)) {
  34. zoo.push(i);
  35. } else {
  36. result.push(i);
  37. }
  38. }
  39. }
  40. shuffleArray(result);
  41. return(merge(result, zoo).join(''));
  42. }
  43.  
  44. function g(s) {
  45. let r = 0;
  46. let i = s.length - 1;
  47. while (i >= 0) {
  48. if (i > 0
  49. && ['10', '11'].includes(s[i-1] + s[i])) {
  50. r += 1 << Number(s[i-1] + s[i]);
  51. i -= 1;
  52. } else {
  53. r += 1 << Number(s[i]);
  54. }
  55. i -= 1;
  56. }
  57. return r;
  58. }
  59.  
  60. const n = 176
  61. const ff = f(n)
  62. print(ff);
  63. print(g(ff));
Success #stdin #stdout 0.04s 16956KB
stdin
Standard input is empty
stdout
457
176