I didn’t get a chance yesterday to complete the March Madness, and today, I started too late because I didn’t have any ideas. Anyway, another person in the ‘space is doing Project Euler problems, so I did the first one in Matlab.
euler1.m:
% Project Euler - Problem 1
% for March Madness (late) Day 2
% If we list all the natural numbers below 10 that are multiples of
% 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
%
% Find the sum of all the multiples of 3 or 5 below 1000.
function euler1()
tosum = zeros(1,999);
tosum(3:3:999) = 1;
tosum(5:5:999) = 1;
sum35 = sum(find(tosum));
sprintf('The sum is %d\n', sum35)
Some notes: This has got to me the most inefficient way of doing it. I’m sure I’m using a shit ton of memory for no goddamn reason. I did it that way because I wanted to use some fancy Matlab function and so it doesn’t look like every other version in every other language.
I’ll have to catch up tomorrow and use a language whose file extension isn’t “.m”.
0 Responses to “March Madness (late) Day 2”