Advertisement
bebo231312312321

Untitled

Feb 4th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rosettaStone(input) {
  2.   const tempLenght = Number(input.shift());
  3.   const template = [];
  4.  
  5.   for (let i = 0; i < tempLenght; i++) {
  6.     const line = input.shift();
  7.     template.push(line.split(' ').map(Number));
  8.   }
  9.  
  10.   const matrix = [];
  11.  
  12.   for (let line of input) {
  13.     matrix.push(line.split(' ').map(Number));
  14.   }
  15.  
  16.   let result = '';
  17.  
  18.   for (let row = 0; row < matrix.length; row++) {
  19.     for (let col = 0; col < matrix[0].length; col++) {
  20.       // current index position
  21.       const index = matrix[row][col];
  22.       // template overlay
  23.       const templateDecoder = template[row % tempLenght][col % template[0].length];
  24.       const output = ((index + templateDecoder) % 27) + 64;
  25.       result += String.fromCharCode(output);
  26.     }
  27.   }
  28.  
  29.   const pattern = /@/g;
  30.   result = result.replace(pattern, ' ');
  31.   console.log(result);
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement