Assuming the 1000-digit number is stored in a string format in Matlab, the following code can be used to find the thirteen adjacent digits that have the greatest product:
main.m472 chars15 lines
Note that this code uses two nested loops to iterate over all possible sets of 13 adjacent digits in the 1000-digit number, and calculates their product using a variable called currProd
. The maximum product found is stored in maxProd
and is displayed at the end.
gistlibby LogSnag