Advertisement
irmantas_radavicius

Untitled

Feb 9th, 2022
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <title>Title</title>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <style>
  8.     </style>
  9.  
  10.    
  11. </head>
  12. <body id="body">
  13.  
  14.     <script>
  15.         // input
  16.         let start = 1, finish = 1003;
  17.         let colCount = 10;
  18.                
  19.         // algorithm
  20.         let max = finish;      
  21.         let temp;
  22.         let columnWidth = 0;
  23.         let output = "";
  24.        
  25.         while(max > 0){
  26.             temp = max % 10                
  27.             max = (max - temp) / 10    
  28.             columnWidth = columnWidth + 1;
  29.         }          
  30.        
  31.         let i = start;
  32.         let row = "";
  33.         let j = 1;
  34.        
  35.         while(i <= finish){            
  36.            
  37.             let remaining = i;     
  38.             let lastDigit;
  39.             let duplicates = 0;
  40.             let iDigitCount = 0;
  41.            
  42.             while(remaining > 0){
  43.                 lastDigit = remaining % 10;                
  44.                 remaining = (remaining - lastDigit) / 10;          
  45.                 iDigitCount = iDigitCount + 1;
  46.                
  47.                 let remaining2 = remaining;    
  48.                 let lastDigit2;
  49.                
  50.                 while(remaining2 > 0){
  51.                     lastDigit2 = remaining2 % 10                   
  52.                     remaining2 = (remaining2 - lastDigit2) / 10    
  53.                     if (lastDigit == lastDigit2){
  54.                         duplicates = duplicates + 1;
  55.                     }
  56.                 }          
  57.             }              
  58.            
  59.             if (duplicates > 0){   
  60.                 let gaps = columnWidth - iDigitCount;
  61.                 while(gaps > 0){
  62.                     row += " ";
  63.                     gaps = gaps - 1;
  64.                 }
  65.                 row += i + " ";
  66.                 j = j + 1;
  67.             }
  68.             i = i + 1;     
  69.             if (j % (colCount+1) == 0){
  70.                 output += row + "\n";
  71.                 j = 1;
  72.                 row = "";
  73.             }
  74.         }
  75.         if (row != ""){
  76.             output += row + "\n";
  77.         }
  78.        
  79.         // output
  80.         console.log(output);
  81.        
  82.  
  83.  
  84.     </script>
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement