Advertisement
Guest User

Rosseta stone

a guest
May 29th, 2018
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. function solve(arr) {
  2. let rowsTemplate = Number(arr[0]);
  3. let templateMatrix = [];
  4. let templateCol = 0;
  5. let counter = 0;
  6. for (let i = 1; i <= rowsTemplate; i++) {
  7. counter++;
  8. templateMatrix.push(arr[i].split(' ').map(Number));
  9. }
  10. templateCol += counter;
  11. counter=0;
  12. let messageMatrix = [];
  13. let messageRows = arr.length-rowsTemplate-1;
  14. let messageCol = 0;
  15. for (let i = rowsTemplate + 1; i < arr.length; i++) {
  16. counter++;
  17. messageMatrix.push(arr[i].split(' ').map(Number));
  18. }
  19. messageCol += counter;
  20. counter=0;
  21. //fill the overlap matrix:
  22. let matrix = messageMatrix;
  23. let outputMessage = '';
  24. for (let row = 0; row < matrix.length; row++) {
  25. for (let col = 0; col < matrix[row].length; col++) {
  26. matrix[row][col] += templateMatrix[row%rowsTemplate][col%templateCol];
  27. }
  28. }
  29. for (let i = 0; i < matrix.length; i++) {
  30. for (let j = 0; j < matrix[i].length; j++) {
  31. let char = '';
  32. if(matrix[i][j]!=0){
  33. let num = matrix[i][j]%27;
  34. matrix[i][j] = String.fromCharCode(num+64);
  35. }
  36. else {
  37. matrix[i][j] = ' ';
  38. }
  39.  
  40. }
  41. }
  42. for (let i = 0; i < matrix.length; i++) {
  43. for (let j = 0; j < matrix[i].length; j++) {
  44. outputMessage += matrix[i][j];
  45. }
  46. }
  47. console.log(outputMessage);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement