After tackling a challenging problem online, I successfully discovered the largest product of any 5 consecutive numbers within a 1000-digit number:
var bignumber = "731671765313306249192251196744265747423553491949349698352031277450632623957831801698480186947885184385861560789112949495459501737958331952853208805511125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311362229893423380308135336276614282806444486645238749303589072962904915604407723907138105158593079608667017242712188399879790879227492190169972088809377665727333010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145358866881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626317761111093705442175069416589604080719840385096241334462981230987879927244283625438";
var bigarray = bignumber.split("");
var prod = [];
var buy = 1;
var z = 4;
for (var i = 0; i < bigarray.length; i+=z) {
mult = bigarray[i];
for (var x = 1; x <= z; x++) {
mult *= bigarray[i+x];
}
prod.push(mult);
}
prod.sort(function(a, b){return b-a});
document.write(prod[0]);
Fascinated by my discovery, I posted about it here, realizing later that this intriguing problem originated from Project Euler. Curious to explore further, I visited the official page here. It puzzled me that when I attempted to adjust the consecutive digits to 13 instead of 5 by changing z to 12, the solution was incorrect. Why did this modification lead to an unexpected outcome?