Mathworks "Cody"‎ > ‎Problems 20-29‎ > ‎

Problem 26

Given the input n, return true if n is odd or false if n is even.

Solution

We've already done this 1,000 times in project Euler. Just do a mod(n,2) check to see if it's even. Check the code!

Code

function[tf] = problem26(n)


    tf = mod(n,2);  % If there is no remained, tf = 0 (even!), if there is a remainder, tf = 1 (true)

    

end

Correct, Size 13

Recommendations

I get a size of 13 when the leading solution is size 12. Not sure what I'm doing wrong but it's so close to the leading solution! I'll come back to this later.

Follow me!
Comments