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.
By
Doug Hull
Doug first used MATLAB in 1994, could not figure it out until he got some help in 1995. He is now dedicated to making sure that no one else wastes a year of their life not knowing MATLAB like he did.
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!
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