daily pastebin goal
54%
SHARE
TWEET

manchev.ask

a guest Feb 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getGets = arr => {
  2.   let index = 0;
  3.  
  4.   return () => {
  5.     const toReturn = arr[index];
  6.     index += 1;
  7.     return toReturn;
  8.   };
  9. };
  10. // this is the test
  11. const test = [
  12.   "6 6",
  13.   "92 11 23 42 59 48",
  14.   "09 92 23 72 56 14",
  15.   "17 63 92 46 85 95",
  16.   "34 12 52 69 23 95",
  17.   "26 88 78 71 29 95",
  18.   "26 34 16 63 39 95"
  19. ];
  20.  
  21. // const test = [
  22. //   "6 6",
  23. //   "92 11 11 42 59 48",
  24. //   "09 92 23 72 56 14",
  25. //   "12 63 92 46 85 95",
  26. //   "34 12 52 52 52 95",
  27. //   "12 88 78 71 29 95",
  28. //   "0 0 0 0 0 0"
  29. // ];
  30.  
  31. const gets = this.gets || getGets(test);
  32. const print = this.print || console.log;
  33.  
  34. const matrix = [];
  35. let [row, col] = gets()
  36.   .split(" ")
  37.   .map(Number);
  38.  
  39. //console.log(row, col);
  40.  
  41. for (let r = 0; r < row; r++) {
  42.   matrix[r] = gets()
  43.     .split(" ")
  44.     .map(Number);
  45. }
  46.  
  47. //console.table(matrix);
  48. let max = 0;
  49.  
  50. const rigth = (r, c) => {
  51.   let len = 1;
  52.   let current = matrix[r][c];
  53.  
  54.  
  55.   while (c < col - 1) {
  56.     if (current === matrix[r][c + 1]) len++;
  57.     else {
  58.       break;
  59.     }
  60.     c++;
  61.   }
  62.   return len;
  63. };
  64.  
  65. const downRight = (r, c) => {
  66.   let len = 1;
  67.   let current = matrix[r][c];
  68.  
  69.  
  70.   while (c < col - 1 && r < row - 1) {
  71.     if (current === matrix[r + 1][c + 1]) len++;
  72.     else {
  73.       break;
  74.     }
  75.     c++;
  76.     r++;
  77.   }
  78.   return len;
  79. };
  80.  
  81. const down = (r, c) => {
  82.   let len = 1;
  83.   let current = matrix[r][c];
  84.  
  85.  
  86.   while (r < row - 1) {
  87.     if (current === matrix[r + 1][c]) len++;
  88.     else {
  89.       break;
  90.     }
  91.     r++;
  92.   }
  93.   return len;
  94. };
  95.  
  96. const downLeft = (r, c) => {
  97.   let len = 1;
  98.   let current = matrix[r][c];
  99.  
  100.  
  101.   while (c > 0 && r < row - 1) {
  102.     if (current === matrix[r + 1][c - 1]) len++;
  103.     else {
  104.       break;
  105.     }
  106.     c--;
  107.     r++;
  108.   }
  109.   return len;
  110. };
  111.  
  112.  
  113. for (let r = 0; r < row; r++) {
  114.   for (let c = 0; c < col; c++) {
  115.     let maxRight = rigth(r, c);
  116.  
  117.     //console.log(right);
  118.     let maxDownRight = downRight(r, c);
  119.     //console.log(downright);
  120.     let maxDown = down(r, c);
  121.     //console.log(down);
  122.     let maxDownLeft = downLeft(r, c);
  123.     //console.log(downleft);    
  124.     max = Math.max(max, maxRight, maxDownRight, maxDown, maxDownLeft);
  125.   }
  126. }
  127.  
  128. print(max);
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