Cody

Problem 246. Project Euler: Problem 8, Find largest product in a large string of numbers

Solution 3043525

Submitted on 3 Oct 2020 by Fazlul Haque
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
a = ['73167176531330624919225119674426574742355349194934'... '96983520312774506326239578318016984801869478851843'... '85861560789112949495459501737958331952853208805511'... '12540698747158523863050715693290963295227443043557'... '66896648950445244523161731856403098711121722383113'... '62229893423380308135336276614282806444486645238749'... '30358907296290491560440772390713810515859307960866'... '70172427121883998797908792274921901699720888093776'... '65727333001053367881220235421809751254540594752243'... '52584907711670556013604839586446706324415722155397'... '53697817977846174064955149290862569321978468622482'... '83972241375657056057440261407972968652414535100474'... '82166370484403199890058895243450658541227588666881'... '16427171479924442928260863465674813919123162824586'... '17866458359124566529486545682848912883142607690042'... '24219022671055626321191109370544217506941658960408'... '07198403850962455444362981230987879927244284909188'... '84580156166097919133855499200524066689912560717606'... '05886116467109405077541002256983155200055935729725'... '71636269561882670428232483600823267530420752963450'] y_correct = 40824; assert(isequal(euler008(a),y_correct))

a = '7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574402614079729686524145351004748216637048440319989005889524345065854122758866688116427171479924442928260863465674813919123162824586178664583591245665294865456828489128831426076900422421902267105562632119110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338554992005240666899125607176060588611646710940507754100225698315520005593572972571636269561882670428232483600823267530420752963450' a = '7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574402614079729686524145351004748216637048440319989005889524345065854122758866688116427171479924442928260863465674813919123162824586178664583591245665294865456828489128831426076900422421902267105562632119110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338554992005240666899125607176060588611646710940507754100225698315520005593572972571636269561882670428232483600823267530420752963450'

2   Pass
a = ['73467176531330624919225119674426574742355349194934'... '96953520312774506326239578318016984801869478851843'... '85866560789112949495459501737958331952853208805511'... '12540898747158523863050715693290963295227443043557'... '66896698950445244523161731856403098711121722383113'... '62229890423380308135336276614282806444486645238749'... '30358907896290491560440772390713810515859307960866'... '70172427621883998797908792274921901699720888093776'... '65727333501053367881220235421809751254540594752243'... '52584907511670556013604839586446706324415722155397'... '53697817477846174064955149290862569321978468622482'... '83972241775657056057490261407972968652414535100474'... '82166370984403199890008895243450658541227588666881'... '16427171079924442928230863465674813919123162824586'... '17866458359124566529476545682848912883142607690042'... '24219022671055626321111109370544217506941658960408'... '07198403850962455444362981230987879927244284909188'... '84580156166097919133875499200524063689912560717606'... '05886116467109405077541002256983155200055935729725'... '71636269561882670428252483600823257530420752963450'] a = reshape(a,10,100); a = a'; a = a(:)'; y_correct = 35721; assert(isequal(euler008(a),y_correct))

a = '7346717653133062491922511967442657474235534919493496953520312774506326239578318016984801869478851843858665607891129494954595017379583319528532088055111254089874715852386305071569329096329522744304355766896698950445244523161731856403098711121722383113622298904233803081353362766142828064444866452387493035890789629049156044077239071381051585930796086670172427621883998797908792274921901699720888093776657273335010533678812202354218097512545405947522435258490751167055601360483958644670632441572215539753697817477846174064955149290862569321978468622482839722417756570560574902614079729686524145351004748216637098440319989000889524345065854122758866688116427171079924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450' a = '7122592219894531709760101633863641971920612005164557968854748405719273194422114100384868220758571220332636736451582215046463723326024330801850295260673852436925240056934171786401467967240745514391853743554979978193055094841022868439080188987507957472645569509310868420868269025125162885950680113682256017954588625384876395792202055071773708232548080296168772656385824812645171511892974874608905532452761413574869018051306238393762847092991073317453617149620681619867463865426960798489909937640576687912979508855419082524641788064399256492693652595935879322516039556143924658902956451901196110222273567464426301697559369394813986480131028293374520652514222464507924672414566802630005229592871520960633697290311804325889558551101147759587779738242708437091410024084181969585830237643437161096605079400451433328847978176325926114344486086694775815451649460987574799328025183221462090840281309047602520453945416063859514322753423252899075627926018431341774872779148042178626598427154854948635166795568820'

3   Pass
a = ['05886116460109405000541002256983155200055935029025'... '96952652026120060506262622695082618016986080186960'... '85866560089112960960956059501026095826295208805511'... '12560089806001585226862605002629522060602606026550'... '66896698950526161026185660026098011121022268261126'... '62229890608026620661602828066060606086660522680609'... '26026589009156060600002269001268105158592600960866'... '00102602062699809090809220609219016990208880926006'... '65020262626501052626608812202265602180905125226026'... '52586090051160055601266060826958660606006261552690'... '52669081060008606106006609551609290862569266226082'... '82690226060506090261600090296865260160526510060060'... '82166260061998900088952602660506585601220588666881'... '16602010129282260862660656060812691912261628260586'... '10866605826591260566529600658912882616026006900602'... '26021902262626211111092600566021050696016589606008'... '00198600268509626055606060260809920260602860909188'... '86058015616609091912626805605640626689912560010606'... '05886116606010960050005601002251552000559265029025'... '01626626956188260060282526082668260602005296266050'] a = reshape(a,10,100); a = a'; a = a(:)'; y_correct = 31104; assert(isequal(euler008(a),y_correct))

a = '0588611646010940500054100225698315520005593502902596952652026120060506262622695082618016986080186960858665600891129609609560595010260958262952088055111256008980600158522686260500262952206060260602655066896698950526161026185660026098011121022268261126622298906080266206616028280660606060866605226806092602658900915606060000226900126810515859260096086600102602062699809090809220609219016990208880926006650202626265010526266088122022656021809051252260265258609005116005560126606082695866060600626155269052669081060008606106006609551609290862569266226082826902260605060902616000902968652601605265100600608216626006199890008895260266050658560122058866688116602010129282260862660656060812691912261628260586108666058265912605665296006589128826160260069006022602190226262621111109260056602105069601658960600800198600268509626055606060260809920260602860909188860580156166090919126268056056406266899125600106060588611660601096005000560100225155200055926502902501626626956188260060282526082668260602005296266050' a = '0058596286899251682260192686602906202818666655125650009806668190019611165162202608602866420605906265514396162051562206966588220005610860609855051216822009225055295656262605220669150509866205500121188280113922688160050250825062226205210199080086256666606266002119258680628998002208106960066681556682298905550610620986162696618268022620009210218058006168696960606868802698616862665999020598208065528566640502028169558050206161296266606592826900122606059600200900690562251262029120068660980060690206220210222662085698008502660168280856916600922521205065009822901620266066966606091060620200956116102666661520950616605258506691021900808005009696622869580286566202606060610010006100159606269116801000920006605002596909065920058021106666960882000026000062661152062900006180862555566216600060159096600006082040602005960612182265926026666000156099206229200609001580665608028160288680021600250686159065252962056095526080800910660056026010690029660206262065190066662618206852122866269226101865808126160025550600'

Suggested Problems

More from this Author52

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!