Advertisement
Spocoman

06. Magic Matrices

Jan 23rd, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let isMagic = true;
  3.     let sum = input[0].reduce((a, b) => a + b,0);
  4.     for(let i = 0; i < input[0].length; i ++) {
  5.         if(sum !== input[i].reduce((a, b) => a + b, 0)){
  6.             isMagic = false;
  7.             break;
  8.         }
  9.         if(isMagic){
  10.             let current = 0;
  11.             for(let j = 0; j < input.length; j ++) {
  12.                 current += input[i][j];
  13.             }
  14.             if(sum !== current){
  15.                 isMagic = false;
  16.                 break;
  17.             }
  18.         } else {
  19.             break;
  20.         }
  21.     }
  22.     console.log(isMagic);
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement