TheAlgorithms / MATLAB-Octave

This repository contains algorithms written in MATLAB/Octave. Developing algorithms in the MATLAB environment empowers you to explore and refine ideas, and enables you test and verify your algorithm.
MIT License
364 stars 173 forks source link

Improve Project Euler problem 4 #87

Closed MaximSmolskiy closed 2 years ago

MaximSmolskiy commented 3 years ago

Project Euler problems solutions-programs shoud work not much more than one minute ("one-minute rule"). But current implementation works more than ten minutes.

It can be sped up if check whether product is palindrome only for products which are greater than current maxPalindrome value and thus can update it.

Before:

>> tic;solv;toc;
The greates palindrome number is 906609
Elapsed time is 635.412 seconds.

After:

>> tic;solv;toc;
The greates palindrome number is 906609
Elapsed time is 8.5047 seconds.
cozek commented 2 years ago

Many thanks!