Lulunga

Final Exam 03. The Isle of Man TT Race geohashCode

Jul 27th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.  
  4.     for (let line of input) {
  5.  
  6.         let pattern = /^([#*&%$])(?<racer>[A-Za-z]+)\1=(?<lengthGeohashCode>\d+)!!(?<geohashCode>.+)$/gm;
  7.         let result = pattern.exec(line);
  8.         if (result) {
  9.             let racer = result.groups.racer;
  10.             let lengthGeohashCode = Number(result.groups.lengthGeohashCode);
  11.             let geohashCode = result.groups.geohashCode;
  12.             let realLength = geohashCode.length;
  13.             let decryptedCode = geohashCode.split('').map(e => String.fromCharCode(e.charCodeAt(0) + lengthGeohashCode)).join('');
  14.  
  15.             realLength === lengthGeohashCode
  16.                 ? console.log(`Coordinates found! ${racer} -> ${decryptedCode}`)
  17.                 : console.log(`Nothing found!`);
  18.  
  19.         }
  20.         else {
  21.             console.log(`Nothing found!`);
  22.         }
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment