Advertisement
Spocoman

05. Rosetta Stone

Dec 20th, 2022
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rosettaStone(input) {
  2.     let templateLen = Number(input[0]);
  3.     let template = input.slice(1, templateLen + 1).map((x) => x.split(" ").map(Number));
  4.     let message = input.slice(templateLen + 1).map((x) => x.split(" ").map(Number));
  5.     let encoder = (n) => " ABCDEFGHIJKLMNOPQRSTUVWXYZ"[(n % 27)];
  6.  
  7.     for (let row = 0; row < message.length; row++) {
  8.         let tRow = template.shift();
  9.         for (let col = 0; col < message[row].length; col += tRow.length) {      
  10.             for (let tCol = 0; tCol < tRow.length && col + tCol < message[row].length; tCol++) {
  11.                 message[row][col + tCol] += tRow[tCol];    
  12.             }
  13.         }
  14.         template.push(tRow);
  15.     }
  16.    
  17.     let encodingMessage = message.flat().map(x => encoder(x)).join("").trimEnd();
  18.     console.log(encodingMessage);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement