fork download
  1. var array, encoded, value, accum, i, j, k, l;
  2.  
  3. // Example data
  4. array=[[0,1,-1,-2,-2,0,-1,2],
  5. [0,-1,-1,2,-1,0,2,-1],
  6. [-2,0,-1,2,2,2,2,0],
  7. [-1,1,-2,-2,-1,2,1,-2],
  8. [0,2,-2,0,-2,1,1,2],
  9. [0,0,-1,-1,0,-1,-2,1],
  10. [0,-1,0,-2,-1,-2,-1,1],
  11. [-2,2,-1,2,0,0,2,1],
  12. [2,2,-2,-1,-1,1,-2,-1],
  13. [-1,1,1,-1,1,-1,-1,-2],
  14. [0,0,1,-2,2,2,-2,-2],
  15. [-2,-2,-2,-1,-2,-1,2,-1],
  16. [0,1,-2,1,1,2,1,-1],
  17. [2,-2,-1,2,1,-2,2,-1],
  18. [0,-1,2,-1,0,-2,1,2],
  19. [0,2,-1,-2,0,-2,-2,0],
  20. [2,0,-2,-2,-2,2,0,2],
  21. [-1,-1,-1,1,-2,1,-1,-1],
  22. [-2,2,1,0,-2,-2,-1,1],
  23. [0,0,2,0,0,1,1,0],
  24. [1,1,1,2,-1,2,-1,2],
  25. [1,1,1,2,-2,1,-1,-2],
  26. [2,-1,-2,0,0,1,-1,0],
  27. [-2,-2,1,-1,-1,0,-1,-1],
  28. [-2,1,-2,0,2,2,1,2],
  29. [-2,1,0,1,0,0,0,2],
  30. [-1,-1,-2,-2,-2,-2,-1,2],
  31. [0,2,-2,2,0,0,0,-2],
  32. [2,2,-2,2,1,1,2,2],
  33. [1,-2,-1,-1,0,2,1,-2],
  34. [-2,2,1,1,0,0,-1,1],
  35. [-1,-1,2,-2,1,-1,-2,-1],
  36. [2,2,-2,2,-2,-1,2,1],
  37. [0,-1,2,0,-2,-1,2,-1],
  38. [0,1,0,2,0,-1,1,-2],
  39. [2,-2,-1,-1,-2,1,0,1],
  40. [-1,2,0,2,2,-2,-2,1],
  41. [1,0,0,1,0,0,2,2],
  42. [1,1,2,-2,-2,1,-1,-2],
  43. [-1,-2,2,-2,-2,-1,-1,0],
  44. [-1,1,-1,2,-1,1,-1,-2],
  45. [-1,2,-2,0,0,-1,-2,-2],
  46. [-2,0,0,0,2,-2,-1,0],
  47. [1,-2,2,2,-2,-1,0,2],
  48. [1,-2,0,1,-2,-1,-2,1],
  49. [0,2,-2,2,-1,1,1,-2],
  50. [2,-2,-1,-1,-2,-2,1,-2],
  51. [1,2,-1,1,0,0,2,0],
  52. [1,-1,1,0,-1,-2,1,-2],
  53. [-1,1,-2,-1,0,0,0,2],
  54. [0,-1,-2,2,-1,-1,2,1],
  55. [2,-2,2,0,1,1,-1,-1],
  56. [2,-1,-2,2,-1,-1,0,0],
  57. [-1,1,-1,-2,1,1,2,2],
  58. [1,2,-1,0,-2,-1,-1,0],
  59. [1,1,-1,-1,2,1,-2,0],
  60. [0,0,2,-1,-1,1,1,1],
  61. [0,-1,0,-2,2,2,0,-2],
  62. [-1,2,-1,1,0,0,2,2],
  63. [0,1,2,2,-2,2,1,-1],
  64. [2,-1,0,-2,-2,1,-2,-2],
  65. [-2,-1,2,1,-2,-2,1,2],
  66. [-1,-2,-2,0,-1,-1,-2,2],
  67. [-1,2,1,0,0,-1,2,0],
  68. [-1,-1,1,1,0,-1,1,0],
  69. [2,1,1,2,-2,1,-1,1],
  70. [-1,-2,2,-2,1,1,-1,-1],
  71. [-1,0,-2,1,2,-2,1,-2],
  72. [0,0,1,-2,-1,-2,-1,-2],
  73. [2,0,1,1,2,2,2,-1],
  74. [-2,0,1,2,-2,-1,-2,2],
  75. [1,0,0,0,-1,1,2,-1],
  76. [1,2,-1,0,-2,-2,0,1],
  77. [2,0,2,0,1,2,-1,2],
  78. [1,2,-1,-1,0,0,0,-1],
  79. [-1,2,2,2,-2,2,0,0],
  80. [-1,0,2,0,0,-2,-1,0],
  81. [-1,0,2,2,1,1,2,0],
  82. [1,0,1,-2,-1,2,0,-1],
  83. [-1,1,-1,0,-2,2,2,1],
  84. [0,0,-2,2,2,-1,1,-1]];
  85.  
  86. // Per problem statement, some entries are known to be zero,
  87. // but we don't know which, so this is a placeholder.
  88. function mustBeZero(i, j) { return false; }
  89.  
  90. accum = 0;
  91. k = 1;
  92. l = 0;
  93. // Using a Uint32Array where supported might be better.
  94. // 50 is ceil(9*9*8/13) since we don't know any fixed zeros in this example
  95. encoded = new Array(50);
  96. for (i = 0; i !== 81; ++i) {
  97. for (j = 0; j !== 8; ++j) {
  98. if (mustBeZero(i, j))
  99. continue;
  100. value = array[i][j] + 2;
  101. accum += k*value;
  102. k *= 5;
  103. if (k !== 1220703125) // 5^13
  104. continue;
  105. encoded[l] = accum;
  106. accum = 0;
  107. ++l;
  108. k = 1;
  109. }
  110. }
  111. if (k !== 1) {
  112. encoded[l] = accum;
  113. ++l;
  114. }
  115. print(encoded.join(",\n") + ";\n");
  116.  
  117. // Now we reconstruct the original data from this.
  118. array = null; // forget original input
  119. l = 0;
  120. k = 0;
  121. for (i = 0; i !== 81; ++i) {
  122. array = []; // one row only
  123. for (j = 0; j !== 8; ++j) {
  124. if (mustBeZero(i, j))
  125. continue;
  126. if (k === 0) {
  127. accum = encoded[l];
  128. ++l;
  129. k = 13;
  130. }
  131. value = (accum % 5);
  132. accum = (accum - value)/5;
  133. --k;
  134. array.push(value - 2);
  135. }
  136. print(array.join(","));
  137. }
  138.  
Success #stdin #stdout 0.02s 5116KB
stdin
Standard input is empty
stdout
452287542,
810535672,
883158650,
112522689,
1167137901,
407517654,
377176,
436773026,
579049279,
703287240,
396983000,
708282976,
946074092,
850317618,
149005011,
1099034247,
692515631,
194831137,
368674306,
1023853658,
578348605,
744463488,
621170542,
78496813,
455643851,
488862008,
546538237,
1020720894,
761815091,
74889084,
77144153,
329233659,
748629259,
900818623,
892381731,
822497163,
1062886237,
37501886,
945412548,
649864287,
772134969,
592157658,
1218188153,
612909176,
1142764616,
599521697,
1088999907,
720660762,
113794463,
16392224;

0,1,-1,-2,-2,0,-1,2
0,-1,-1,2,-1,0,2,-1
-2,0,-1,2,2,2,2,0
-1,1,-2,-2,-1,2,1,-2
0,2,-2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