Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let output = [];
- //CONCATTER FUNCTION
- let concatter = (arr, length)=>{
- let size = arr.length;
- while(arr.length<length){
- for(let i = 0; i<size; i++){
- let current = arr[i];
- if(arr.length>=length){
- break;
- }else{
- arr.push(current);
- }
- }
- }
- return arr;
- }
- /////////
- //
- let rosetaStone = [' '];
- for(let i = 65; i<=90; i++){
- rosetaStone.push(String.fromCharCode(i));
- }
- //
- let arr = input.slice(0);
- let templateSize = Number(arr.shift());
- let template = arr.splice(0,templateSize).map(item=>{
- return item.split(' ').map(Number);
- });
- let matrix = arr.map(item=>{
- return item.split(' ').map(Number);
- });
- let matrixRowSize = matrix[0].length;
- let templateMatrix = template.map(item=>{
- return concatter(item,matrixRowSize);
- });
- let fullTemplate = concatter(templateMatrix,matrix.length);
- for(let row = 0; row < matrix.length; row++){
- for(let col = 0; col < matrix[row].length; col++){
- let currentTemplate = fullTemplate[row][col];
- matrix[row][col] += currentTemplate;
- matrix[row][col] = matrix[row][col]%27;
- let index = matrix[row][col];
- output.push(rosetaStone[index]);
- }
- }
- return output.join('');
- }
Advertisement
Add Comment
Please, Sign In to add comment