Combine Set of 5 loops "for"

0

I'm creating a unique ID for each id, which works like this: the last 2 digits validate the previous 9 with an algorithm.

I am creating a function that finds the first 5 digits, according to the last 6 data, in all possible combinations!

The code works, but not as it should ... I made 5 for loops, as below:

function executar(v){ // função principal
        logg("Inicio da Operacao...");
         for(var x=get('x');x<10;x++){
           for(var y=get('y');y<10;y++){
             for(var z=get('z');z<10;z++){
              for(var k=get('k');k<10;k++){
                for(var w=get('w');w<10;w++){
                 var clc = ""+x+""+y+""+z+""+k+""+w+""+v;
                 if(validarID(clc)){
                  logg(clc+": é uma possibilidade válida!");
                  pause(x,y,z,k,w);
                  return true;
                 }
                 logg(clc+": não e válido.");
               }
              }
             }
            }
           }
         logg("Fim da Operacao.");
         return false;
    }

function pause(x,y,z,k,w){
   set('x',x);
   set('y',y);
   set('z',z);
   set('k',k);
   set('w',parseInt(w)+1);
}
function set(id, valor){//guarda variáveis pra continuar depois
   document.getElementById(id).value=valor;
}
function get(id){//recupera valores apos pause
   return parseInt(document.getElementById(id).value);
}
function logg(msg){
      var obj = document.getElementById('log');
          obj.value = obj.value + "\n";
          obj.value = obj.value +  ">> " +msg;
          setTimeout(function(){
                obj.scrollTop = obj.scrollHeight;
            }, 500);
}

function validarID(id) { 
    // 
}

Output:

// - - - - Exemplo de saída - - - //
// - - - - Dado: (833703): - - - - //
// - - - - Tinha colocado hora min seg etc mas não e importante - - - //


10s075ms>> Inicio da Operacao...
10s076ms>> 00001833703: failed.
10s076ms>> 00002833703: failed.
10s076ms>> 00003833703: failed.
10s076ms>> 00004833703: failed.
10s076ms>> 00005833703: failed.
10s076ms>> 00006833703: failed.
10s077ms>> 00007833703: failed.
10s077ms>> 00008833703: failed.
10s077ms>> 00009833703: failed.
10s077ms>> 00011833703: failed.
10s077ms>> 00012833703: failed.
10s077ms>> 00013833703: failed.
10s077ms>> 00014833703: failed.
10s078ms>> 00015833703: failed.
10s078ms>> 00016833703: failed.
10s078ms>> 00017833703: failed.
10s078ms>> 00018833703: failed.
10s078ms>> 00019833703: failed.
10s078ms>> 00021833703: failed.
10s079ms>> 00022833703: failed.
10s079ms>> 00023833703: failed.
10s079ms>> 00024833703: failed.
10s079ms>> 00025833703: failed.
10s079ms>> 00026833703: failed.
10s079ms>> 00027833703: failed.
10s079ms>> 00028833703: failed.
10s079ms>> 00029833703: failed.
10s079ms>> 00031833703: failed.
10s080ms>> 00032833703: failed.
10s080ms>> 00033833703: failed.
10s080ms>> 00034833703: failed.
10s080ms>> 00035833703: failed.
10s080ms>> 00036833703: is correct!
11s622ms>> Inicio da Operacao...
11s622ms>> 00037833703: failed.
11s623ms>> 00038833703: failed.
11s623ms>> 00039833703: failed.
11s624ms>> 00047833703: failed.
11s624ms>> 00048833703: failed.
11s624ms>> 00049833703: failed.
11s624ms>> 00057833703: failed.
11s625ms>> 00058833703: failed.
11s625ms>> 00059833703: failed.
11s625ms>> 00067833703: failed.
11s625ms>> 00068833703: failed.
11s625ms>> 00069833703: failed.
11s626ms>> 00077833703: failed.
11s626ms>> 00078833703: failed.
11s626ms>> 00079833703: failed.
11s626ms>> 00087833703: failed.
11s627ms>> 00088833703: failed.
11s627ms>> 00089833703: failed.
11s627ms>> 00097833703: failed.
11s627ms>> 00098833703: failed.
11s627ms>> 00099833703: failed.
11s628ms>> 00137833703: failed.
11s628ms>> 00138833703: failed.
11s628ms>> 00139833703: failed.
11s628ms>> 00147833703: failed.
11s629ms>> 00148833703: failed.
11s629ms>> 00149833703: failed.
11s629ms>> 00157833703: failed.
11s629ms>> 00158833703: failed.
11s630ms>> 00159833703: failed.
11s630ms>> 00167833703: failed.
11s630ms>> 00168833703: failed.
11s630ms>> 00169833703: failed.
11s631ms>> 00177833703: failed.
11s631ms>> 00178833703: failed.
11s632ms>> 00179833703: failed.
11s632ms>> 00187833703: failed.
11s632ms>> 00188833703: failed.
11s632ms>> 00189833703: failed.
11s633ms>> 00197833703: failed.
11s633ms>> 00198833703: failed.
11s633ms>> 00199833703: failed.
11s633ms>> 00237833703: failed.
11s634ms>> 00238833703: failed.
11s634ms>> 00239833703: failed.
11s634ms>> 00247833703: failed.
11s634ms>> 00248833703: failed.
11s635ms>> 00249833703: failed.
11s635ms>> 00257833703: failed.
11s636ms>> 00258833703: failed.
11s636ms>> 00259833703: failed.
11s636ms>> 00267833703: failed.
11s637ms>> 00268833703: failed.
11s637ms>> 00269833703: failed.
11s637ms>> 00277833703: failed.
11s637ms>> 00278833703: failed.
11s638ms>> 00279833703: failed.
11s638ms>> 00287833703: failed.
11s638ms>> 00288833703: failed.
11s638ms>> 00289833703: failed.
11s639ms>> 00297833703: failed.
11s639ms>> 00298833703: failed.
11s639ms>> 00299833703: failed.
11s639ms>> 00337833703: failed.
11s640ms>> 00338833703: failed.
11s640ms>> 00339833703: failed.
11s640ms>> 00347833703: failed.
11s641ms>> 00348833703: failed.
11s641ms>> 00349833703: failed.
11s641ms>> 00357833703: failed.
11s642ms>> 00358833703: failed.
11s642ms>> 00359833703: failed.
11s642ms>> 00367833703: failed.
11s642ms>> 00368833703: failed.
11s643ms>> 00369833703: failed.
11s643ms>> 00377833703: failed.
11s643ms>> 00378833703: failed.
11s644ms>> 00379833703: failed.
11s644ms>> 00387833703: failed.
11s644ms>> 00388833703: failed.
11s644ms>> 00389833703: is correct!
12s544ms>> Inicio da Operacao...
12s550ms>> Fim da Operacao.

Updated: Adjusting the typing of values (str / int) and omitting pause function worked. I wanted to pause and resume, but the important thing I wanted was what worked.

    
asked by anonymous 19.03.2017 / 00:39

0 answers