Advertisement
Guest User

Bulgarian Solitaire

a guest
Aug 13th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const N = parseInt(readline());
  2. var inputs = readline().split(' ');
  3. let supZero = 0;
  4. let arrayTemp = [];
  5. let search = true;
  6.  
  7.  
  8. while ( search ){    
  9.  
  10.     inputs = down(inputs);  
  11.    
  12.     for (let index = 0; index < arrayTemp.length; index++) {        
  13.        
  14.         if ( inputs.filter(x => x !=0).sort().join('') === arrayTemp[index].filter(x => x != 0 ).sort().join('')){
  15.             search = false;  
  16.             console.log(arrayTemp.length - index);            
  17.             break;                
  18.         }            
  19.        
  20.     }  
  21.  
  22.     arrayTemp.push(inputs.filter(x => x !=0));
  23.  
  24.     if ( arrayTemp.length > 100){
  25.         arrayTemp = [];
  26.     }
  27.    
  28.    
  29. }
  30.  
  31.  
  32. function down(arr){
  33.     arr.map(function(value,i){    
  34.         if ( value != 0 ){
  35.             arr[i] = value - 1 ;
  36.             supZero++;
  37.         }  
  38.     })
  39.     arr.push(supZero);  
  40.     supZero = 0;  
  41.     return arr;
  42. }
  43.  
  44.  
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement