# Doug's MATLAB Video Tutorials

## 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

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 6 + 8 ?

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).

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

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