Stuart’s MATLAB Videos

Watch and Learn

Highlighting solutions to Project Euler problems 001-005 2

Posted by Doug Hull,

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 CommentsOldest to Newest

Alex replied on : 1 of 2

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

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.


Ahmed Abdullah replied on : 2 of 2

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

Add A Comment

What is 5 + 7?

Preview: hide