Doug's MATLAB Video Tutorials

February 14th, 2012

Highlighting solutions to Project Euler problems 001-005

I’ve been excited by the great response to the Project Euler problems that I’ve posted on Cody. This video takes a look at my favorite submission for each of the first five problems. Take a look at how other people have solved these problems, you might see some MATLAB techniques that are new to you.

2 Responses to “Highlighting solutions to Project Euler problems 001-005”

  1. Alex replied on :

    Hi Doug,

    Thanks for the ideas. I like how Problem 1 was solved, but I think it should be modified slightly as follows:

    function y = euler001(x)
    y = sum(union(3:3:x,5:5:x))
    end

    Otherwise, I get y = 4+7+10… instead of y = 3+5+6+…

    I may have overlooked something, but thought I’d point this out just in case.

    Thanks!

  2. Ahmed Abdullah replied on :

    hi Alex,
    No the code for the first problem is okay
    union(1:3:10,1:5:10)= 1 4 6 7 10;
    and union(1:3:10,1:5:10)-1 = 0 3 5 6 9;

    so sum(union(1:3:10,1:5:10)-1)=0+3+5+6+9 =23

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of MathWorks.