ALSAVOV

Untitled

Nov 10th, 2023 (edited)
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let [a, b, maxPassGenerated] = input.map(Number);
  4.     let combinationsCounter = 0;
  5.     let output = "";
  6.  
  7.     let maxComb_a_b = a * b;
  8.     let haveQuit = false;
  9.  
  10.     for (let i = 35; i <= 55; i++) {
  11.         let _A = i;
  12.         let _B = i + 29;
  13.  
  14.         for (let x = 1; x <= a; x++) {
  15.             for (let y = 1; y <= b; y++) {
  16.  
  17.                 if (output.includes(String.fromCharCode(_A))) {
  18.                     _A++;
  19.                 }
  20.  
  21.                 if (_A > 55) {
  22.                     _A = 35;
  23.                 }
  24.  
  25.                 if (output.includes(String.fromCharCode(_B))) {
  26.                     _B++;
  27.                 }
  28.  
  29.                 if (_B > 96) {
  30.                     _B = 64;
  31.                 }
  32.  
  33.                 combinationsCounter++;
  34.  
  35.                 output += `${String.fromCharCode(_A)}${String.fromCharCode(
  36.                     _B
  37.                 )}${x}${y}${String.fromCharCode(_B)}${String.fromCharCode(_A)}|`;
  38.  
  39.                 if (maxComb_a_b > maxPassGenerated) {
  40.                     if (maxPassGenerated === combinationsCounter) {
  41.                         haveQuit = true;
  42.                         break;
  43.                     }
  44.                 } else {
  45.                     if (maxComb_a_b === combinationsCounter) {
  46.                         haveQuit = true;
  47.                         break;
  48.                     }
  49.                 }
  50.             }
  51.             if (haveQuit) {
  52.                 break;
  53.             }
  54.         }
  55.         if (haveQuit) {
  56.             break;
  57.         }
  58.     }
  59.     console.log(output);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment