Advertisement
maymunskoa

Rosetta Stone

Feb 20th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let output = [];
  3.     //CONCATTER FUNCTION
  4. let concatter = (arr, length)=>{
  5.     let size = arr.length;
  6.     while(arr.length<length){
  7.        for(let i = 0; i<size; i++){
  8.            let current = arr[i];
  9.            if(arr.length>=length){
  10.                break;
  11.            }else{
  12.                arr.push(current);
  13.            }
  14.        }
  15.     }
  16.    
  17.     return arr;
  18. }
  19. /////////
  20.  
  21. //
  22.     let rosetaStone = [' '];
  23.     for(let i = 65; i<=90; i++){
  24.         rosetaStone.push(String.fromCharCode(i));
  25.     }
  26. //
  27.  
  28.  
  29. let arr = input.slice(0);
  30. let templateSize = Number(arr.shift());
  31. let template = arr.splice(0,templateSize).map(item=>{                
  32.     return item.split(' ').map(Number);
  33.  });
  34.  
  35.  let matrix = arr.map(item=>{
  36.     return item.split(' ').map(Number);
  37. });
  38.  
  39. let matrixRowSize = matrix[0].length;
  40.  
  41. let templateMatrix = template.map(item=>{
  42.     return concatter(item,matrixRowSize);
  43. });
  44.  
  45.     let fullTemplate = concatter(templateMatrix,matrix.length);
  46.  
  47.  
  48.     for(let row = 0; row < matrix.length; row++){
  49.         for(let col = 0; col < matrix[row].length; col++){
  50.             let currentTemplate = fullTemplate[row][col];
  51.             matrix[row][col] += currentTemplate;
  52.             matrix[row][col] = matrix[row][col]%27;
  53.             let index = matrix[row][col];
  54.             output.push(rosetaStone[index]);
  55.         }
  56.        
  57.     }
  58.     return output.join('');
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement