kanatunta

bounce.steven.ver

Feb 26th, 2019
654
0
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 = ["3 4"];
  12.  
  13. const gets = this.gets || getGets(test);
  14. const print = this.print || console.log;
  15.  
  16. const [row, col] = gets()
  17.   .split(" ")
  18.   .map(Number);
  19.  
  20. let r = 0;
  21. let c = 0;
  22.  
  23. let ir = 1;
  24. let ic = 1;
  25.  
  26. let sum = 1;
  27.  
  28. while (
  29.   !(
  30.     (!r && c === col - 1) ||
  31.     (r === row - 1 && !c) ||
  32.     (r === row - 1 && c === col - 1)
  33.   )
  34. ) {
  35.   r += ir;
  36.   c += ic;
  37.   if (r === row - 1) ir = -1;
  38.   if (c === col - 1) ic = -1;
  39.   if (!r) ir = 1;
  40.   if (!c) ic = 1;  
  41.   sum = bigInt(2).pow(r+c).add(sum);
  42. }
  43.  
  44. print(sum.toString());
Advertisement
Add Comment
Please, Sign In to add comment