# Project Euler: Problem 8

https://projecteuler.net/problem=8

The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.

(see the number below)

Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?

Use NumPy for this computation

``````

In [2]:

import numpy as np

``````
``````

In [3]:

d1000 = "\
73167176531330624919225119674426574742355349194934\
96983520312774506326239578318016984801869478851843\
85861560789112949495459501737958331952853208805511\
12540698747158523863050715693290963295227443043557\
66896648950445244523161731856403098711121722383113\
62229893423380308135336276614282806444486645238749\
30358907296290491560440772390713810515859307960866\
70172427121883998797908792274921901699720888093776\
65727333001053367881220235421809751254540594752243\
52584907711670556013604839586446706324415722155397\
53697817977846174064955149290862569321978468622482\
83972241375657056057490261407972968652414535100474\
82166370484403199890008895243450658541227588666881\
16427171479924442928230863465674813919123162824586\
17866458359124566529476545682848912883142607690042\
24219022671055626321111109370544217506941658960408\
07198403850962455444362981230987879927244284909188\
84580156166097919133875499200524063689912560717606\
05886116467109405077541002256983155200055935729725\
71636269561882670428252483600823257530420752963450\
"

``````
``````

In [16]:

def strproduct(lst):
return np.cumprod(lst)[-1]
bestprod=0
num = np.empty((len(d1000)-14, 13))
for n in np.arange(len(d1000)-14):
print(n/(len(d1000)-14))
for i in range(13):
num[n,i] = d1000[n+(i+1)]
prod = strproduct(num[n])
if prod > bestprod:
bestprod=prod
print(bestprod)

``````
``````

0.0
0.00101419878296
0.00202839756592
0.00304259634888
0.00405679513185
0.00507099391481
0.00608519269777
0.00709939148073
0.00811359026369
0.00912778904665
0.0101419878296
0.0111561866126
0.0121703853955
0.0131845841785
0.0141987829615
0.0152129817444
0.0162271805274
0.0172413793103
0.0182555780933
0.0192697768763
0.0202839756592
0.0212981744422
0.0223123732252
0.0233265720081
0.0243407707911
0.025354969574
0.026369168357
0.02738336714
0.0283975659229
0.0294117647059
0.0304259634888
0.0314401622718
0.0324543610548
0.0334685598377
0.0344827586207
0.0354969574037
0.0365111561866
0.0375253549696
0.0385395537525
0.0395537525355
0.0405679513185
0.0415821501014
0.0425963488844
0.0436105476673
0.0446247464503
0.0456389452333
0.0466531440162
0.0476673427992
0.0486815415822
0.0496957403651
0.0507099391481
0.051724137931
0.052738336714
0.053752535497
0.0547667342799
0.0557809330629
0.0567951318458
0.0578093306288
0.0588235294118
0.0598377281947
0.0608519269777
0.0618661257606
0.0628803245436
0.0638945233266
0.0649087221095
0.0659229208925
0.0669371196755
0.0679513184584
0.0689655172414
0.0699797160243
0.0709939148073
0.0720081135903
0.0730223123732
0.0740365111562
0.0750507099391
0.0760649087221
0.0770791075051
0.078093306288
0.079107505071
0.080121703854
0.0811359026369
0.0821501014199
0.0831643002028
0.0841784989858
0.0851926977688
0.0862068965517
0.0872210953347
0.0882352941176
0.0892494929006
0.0902636916836
0.0912778904665
0.0922920892495
0.0933062880325
0.0943204868154
0.0953346855984
0.0963488843813
0.0973630831643
0.0983772819473
0.0993914807302
0.100405679513
0.101419878296
0.102434077079
0.103448275862
0.104462474645
0.105476673428
0.106490872211
0.107505070994
0.108519269777
0.10953346856
0.110547667343
0.111561866126
0.112576064909
0.113590263692
0.114604462475
0.115618661258
0.116632860041
0.117647058824
0.118661257606
0.119675456389
0.120689655172
0.121703853955
0.122718052738
0.123732251521
0.124746450304
0.125760649087
0.12677484787
0.127789046653
0.128803245436
0.129817444219
0.130831643002
0.131845841785
0.132860040568
0.133874239351
0.134888438134
0.135902636917
0.1369168357
0.137931034483
0.138945233266
0.139959432049
0.140973630832
0.141987829615
0.143002028398
0.144016227181
0.145030425963
0.146044624746
0.147058823529
0.148073022312
0.149087221095
0.150101419878
0.151115618661
0.152129817444
0.153144016227
0.15415821501
0.155172413793
0.156186612576
0.157200811359
0.158215010142
0.159229208925
0.160243407708
0.161257606491
0.162271805274
0.163286004057
0.16430020284
0.165314401623
0.166328600406
0.167342799189
0.168356997972
0.169371196755
0.170385395538
0.17139959432
0.172413793103
0.173427991886
0.174442190669
0.175456389452
0.176470588235
0.177484787018
0.178498985801
0.179513184584
0.180527383367
0.18154158215
0.182555780933
0.183569979716
0.184584178499
0.185598377282
0.186612576065
0.187626774848
0.188640973631
0.189655172414
0.190669371197
0.19168356998
0.192697768763
0.193711967546
0.194726166329
0.195740365112
0.196754563895
0.197768762677
0.19878296146
0.199797160243
0.200811359026
0.201825557809
0.202839756592
0.203853955375
0.204868154158
0.205882352941
0.206896551724
0.207910750507
0.20892494929
0.209939148073
0.210953346856
0.211967545639
0.212981744422
0.213995943205
0.215010141988
0.216024340771
0.217038539554
0.218052738337
0.21906693712
0.220081135903
0.221095334686
0.222109533469
0.223123732252
0.224137931034
0.225152129817
0.2261663286
0.227180527383
0.228194726166
0.229208924949
0.230223123732
0.231237322515
0.232251521298
0.233265720081
0.234279918864
0.235294117647
0.23630831643
0.237322515213
0.238336713996
0.239350912779
0.240365111562
0.241379310345
0.242393509128
0.243407707911
0.244421906694
0.245436105477
0.24645030426
0.247464503043
0.248478701826
0.249492900609
0.250507099391
0.251521298174
0.252535496957
0.25354969574
0.254563894523
0.255578093306
0.256592292089
0.257606490872
0.258620689655
0.259634888438
0.260649087221
0.261663286004
0.262677484787
0.26369168357
0.264705882353
0.265720081136
0.266734279919
0.267748478702
0.268762677485
0.269776876268
0.270791075051
0.271805273834
0.272819472617
0.2738336714
0.274847870183
0.275862068966
0.276876267748
0.277890466531
0.278904665314
0.279918864097
0.28093306288
0.281947261663
0.282961460446
0.283975659229
0.284989858012
0.286004056795
0.287018255578
0.288032454361
0.289046653144
0.290060851927
0.29107505071
0.292089249493
0.293103448276
0.294117647059
0.295131845842
0.296146044625
0.297160243408
0.298174442191
0.299188640974
0.300202839757
0.30121703854
0.302231237323
0.303245436105
0.304259634888
0.305273833671
0.306288032454
0.307302231237
0.30831643002
0.309330628803
0.310344827586
0.311359026369
0.312373225152
0.313387423935
0.314401622718
0.315415821501
0.316430020284
0.317444219067
0.31845841785
0.319472616633
0.320486815416
0.321501014199
0.322515212982
0.323529411765
0.324543610548
0.325557809331
0.326572008114
0.327586206897
0.32860040568
0.329614604462
0.330628803245
0.331643002028
0.332657200811
0.333671399594
0.334685598377
0.33569979716
0.336713995943
0.337728194726
0.338742393509
0.339756592292
0.340770791075
0.341784989858
0.342799188641
0.343813387424
0.344827586207
0.34584178499
0.346855983773
0.347870182556
0.348884381339
0.349898580122
0.350912778905
0.351926977688
0.352941176471
0.353955375254
0.354969574037
0.355983772819
0.356997971602
0.358012170385
0.359026369168
0.360040567951
0.361054766734
0.362068965517
0.3630831643
0.364097363083
0.365111561866
0.366125760649
0.367139959432
0.368154158215
0.369168356998
0.370182555781
0.371196754564
0.372210953347
0.37322515213
0.374239350913
0.375253549696
0.376267748479
0.377281947262
0.378296146045
0.379310344828
0.380324543611
0.381338742394
0.382352941176
0.383367139959
0.384381338742
0.385395537525
0.386409736308
0.387423935091
0.388438133874
0.389452332657
0.39046653144
0.391480730223
0.392494929006
0.393509127789
0.394523326572
0.395537525355
0.396551724138
0.397565922921
0.398580121704
0.399594320487
0.40060851927
0.401622718053
0.402636916836
0.403651115619
0.404665314402
0.405679513185
0.406693711968
0.407707910751
0.408722109533
0.409736308316
0.410750507099
0.411764705882
0.412778904665
0.413793103448
0.414807302231
0.415821501014
0.416835699797
0.41784989858
0.418864097363
0.419878296146
0.420892494929
0.421906693712
0.422920892495
0.423935091278
0.424949290061
0.425963488844
0.426977687627
0.42799188641
0.429006085193
0.430020283976
0.431034482759
0.432048681542
0.433062880325
0.434077079108
0.43509127789
0.436105476673
0.437119675456
0.438133874239
0.439148073022
0.440162271805
0.441176470588
0.442190669371
0.443204868154
0.444219066937
0.44523326572
0.446247464503
0.447261663286
0.448275862069
0.449290060852
0.450304259635
0.451318458418
0.452332657201
0.453346855984
0.454361054767
0.45537525355
0.456389452333
0.457403651116
0.458417849899
0.459432048682
0.460446247465
0.461460446247
0.46247464503
0.463488843813
0.464503042596
0.465517241379
0.466531440162
0.467545638945
0.468559837728
0.469574036511
0.470588235294
0.471602434077
0.47261663286
0.473630831643
0.474645030426
0.475659229209
0.476673427992
0.477687626775
0.478701825558
0.479716024341
0.480730223124
0.481744421907
0.48275862069
0.483772819473
0.484787018256
0.485801217039
0.486815415822
0.487829614604
0.488843813387
0.48985801217
0.490872210953
0.491886409736
0.492900608519
0.493914807302
0.494929006085
0.495943204868
0.496957403651
0.497971602434
0.498985801217
0.5
0.501014198783
0.502028397566
0.503042596349
0.504056795132
0.505070993915
0.506085192698
0.507099391481
0.508113590264
0.509127789047
0.51014198783
0.511156186613
0.512170385396
0.513184584178
0.514198782961
0.515212981744
0.516227180527
0.51724137931
0.518255578093
0.519269776876
0.520283975659
0.521298174442
0.522312373225
0.523326572008
0.524340770791
0.525354969574
0.526369168357
0.52738336714
0.528397565923
0.529411764706
0.530425963489
0.531440162272
0.532454361055
0.533468559838
0.534482758621
0.535496957404
0.536511156187
0.53752535497
0.538539553753
0.539553752535
0.540567951318
0.541582150101
0.542596348884
0.543610547667
0.54462474645
0.545638945233
0.546653144016
0.547667342799
0.548681541582
0.549695740365
0.550709939148
0.551724137931
0.552738336714
0.553752535497
0.55476673428
0.555780933063
0.556795131846
0.557809330629
0.558823529412
0.559837728195
0.560851926978
0.561866125761
0.562880324544
0.563894523327
0.56490872211
0.565922920892
0.566937119675
0.567951318458
0.568965517241
0.569979716024
0.570993914807
0.57200811359
0.573022312373
0.574036511156
0.575050709939
0.576064908722
0.577079107505
0.578093306288
0.579107505071
0.580121703854
0.581135902637
0.58215010142
0.583164300203
0.584178498986
0.585192697769
0.586206896552
0.587221095335
0.588235294118
0.589249492901
0.590263691684
0.591277890467
0.592292089249
0.593306288032
0.594320486815
0.595334685598
0.596348884381
0.597363083164
0.598377281947
0.59939148073
0.600405679513
0.601419878296
0.602434077079
0.603448275862
0.604462474645
0.605476673428
0.606490872211
0.607505070994
0.608519269777
0.60953346856
0.610547667343
0.611561866126
0.612576064909
0.613590263692
0.614604462475
0.615618661258
0.616632860041
0.617647058824
0.618661257606
0.619675456389
0.620689655172
0.621703853955
0.622718052738
0.623732251521
0.624746450304
0.625760649087
0.62677484787
0.627789046653
0.628803245436
0.629817444219
0.630831643002
0.631845841785
0.632860040568
0.633874239351
0.634888438134
0.635902636917
0.6369168357
0.637931034483
0.638945233266
0.639959432049
0.640973630832
0.641987829615
0.643002028398
0.644016227181
0.645030425963
0.646044624746
0.647058823529
0.648073022312
0.649087221095
0.650101419878
0.651115618661
0.652129817444
0.653144016227
0.65415821501
0.655172413793
0.656186612576
0.657200811359
0.658215010142
0.659229208925
0.660243407708
0.661257606491
0.662271805274
0.663286004057
0.66430020284
0.665314401623
0.666328600406
0.667342799189
0.668356997972
0.669371196755
0.670385395538
0.67139959432
0.672413793103
0.673427991886
0.674442190669
0.675456389452
0.676470588235
0.677484787018
0.678498985801
0.679513184584
0.680527383367
0.68154158215
0.682555780933
0.683569979716
0.684584178499
0.685598377282
0.686612576065
0.687626774848
0.688640973631
0.689655172414
0.690669371197
0.69168356998
0.692697768763
0.693711967546
0.694726166329
0.695740365112
0.696754563895
0.697768762677
0.69878296146
0.699797160243
0.700811359026
0.701825557809
0.702839756592
0.703853955375
0.704868154158
0.705882352941
0.706896551724
0.707910750507
0.70892494929
0.709939148073
0.710953346856
0.711967545639
0.712981744422
0.713995943205
0.715010141988
0.716024340771
0.717038539554
0.718052738337
0.71906693712
0.720081135903
0.721095334686
0.722109533469
0.723123732252
0.724137931034
0.725152129817
0.7261663286
0.727180527383
0.728194726166
0.729208924949
0.730223123732
0.731237322515
0.732251521298
0.733265720081
0.734279918864
0.735294117647
0.73630831643
0.737322515213
0.738336713996
0.739350912779
0.740365111562
0.741379310345
0.742393509128
0.743407707911
0.744421906694
0.745436105477
0.74645030426
0.747464503043
0.748478701826
0.749492900609
0.750507099391
0.751521298174
0.752535496957
0.75354969574
0.754563894523
0.755578093306
0.756592292089
0.757606490872
0.758620689655
0.759634888438
0.760649087221
0.761663286004
0.762677484787
0.76369168357
0.764705882353
0.765720081136
0.766734279919
0.767748478702
0.768762677485
0.769776876268
0.770791075051
0.771805273834
0.772819472617
0.7738336714
0.774847870183
0.775862068966
0.776876267748
0.777890466531
0.778904665314
0.779918864097
0.78093306288
0.781947261663
0.782961460446
0.783975659229
0.784989858012
0.786004056795
0.787018255578
0.788032454361
0.789046653144
0.790060851927
0.79107505071
0.792089249493
0.793103448276
0.794117647059
0.795131845842
0.796146044625
0.797160243408
0.798174442191
0.799188640974
0.800202839757
0.80121703854
0.802231237323
0.803245436105
0.804259634888
0.805273833671
0.806288032454
0.807302231237
0.80831643002
0.809330628803
0.810344827586
0.811359026369
0.812373225152
0.813387423935
0.814401622718
0.815415821501
0.816430020284
0.817444219067
0.81845841785
0.819472616633
0.820486815416
0.821501014199
0.822515212982
0.823529411765
0.824543610548
0.825557809331
0.826572008114
0.827586206897
0.82860040568
0.829614604462
0.830628803245
0.831643002028
0.832657200811
0.833671399594
0.834685598377
0.83569979716
0.836713995943
0.837728194726
0.838742393509
0.839756592292
0.840770791075
0.841784989858
0.842799188641
0.843813387424
0.844827586207
0.84584178499
0.846855983773
0.847870182556
0.848884381339
0.849898580122
0.850912778905
0.851926977688
0.852941176471
0.853955375254
0.854969574037
0.855983772819
0.856997971602
0.858012170385
0.859026369168
0.860040567951
0.861054766734
0.862068965517
0.8630831643
0.864097363083
0.865111561866
0.866125760649
0.867139959432
0.868154158215
0.869168356998
0.870182555781
0.871196754564
0.872210953347
0.87322515213
0.874239350913
0.875253549696
0.876267748479
0.877281947262
0.878296146045
0.879310344828
0.880324543611
0.881338742394
0.882352941176
0.883367139959
0.884381338742
0.885395537525
0.886409736308
0.887423935091
0.888438133874
0.889452332657
0.89046653144
0.891480730223
0.892494929006
0.893509127789
0.894523326572
0.895537525355
0.896551724138
0.897565922921
0.898580121704
0.899594320487
0.90060851927
0.901622718053
0.902636916836
0.903651115619
0.904665314402
0.905679513185
0.906693711968
0.907707910751
0.908722109533
0.909736308316
0.910750507099
0.911764705882
0.912778904665
0.913793103448
0.914807302231
0.915821501014
0.916835699797
0.91784989858
0.918864097363
0.919878296146
0.920892494929
0.921906693712
0.922920892495
0.923935091278
0.924949290061
0.925963488844
0.926977687627
0.92799188641
0.929006085193
0.930020283976
0.931034482759
0.932048681542
0.933062880325
0.934077079108
0.93509127789
0.936105476673
0.937119675456
0.938133874239
0.939148073022
0.940162271805
0.941176470588
0.942190669371
0.943204868154
0.944219066937
0.94523326572
0.946247464503
0.947261663286
0.948275862069
0.949290060852
0.950304259635
0.951318458418
0.952332657201
0.953346855984
0.954361054767
0.95537525355
0.956389452333
0.957403651116
0.958417849899
0.959432048682
0.960446247465
0.961460446247
0.96247464503
0.963488843813
0.964503042596
0.965517241379
0.966531440162
0.967545638945
0.968559837728
0.969574036511
0.970588235294
0.971602434077
0.97261663286
0.973630831643
0.974645030426
0.975659229209
0.976673427992
0.977687626775
0.978701825558
0.979716024341
0.980730223124
0.981744421907
0.98275862069
0.983772819473
0.984787018256
0.985801217039
0.986815415822
0.987829614604
0.988843813387
0.98985801217
0.990872210953
0.991886409736
0.992900608519
0.993914807302
0.994929006085
0.995943204868
0.996957403651
0.997971602434
0.998985801217
23514624000.0

``````
``````

In [ ]:

assert True # leave this for grading

``````