This solution is outdated. To rescore this solution, sign in.
-
4 Comments
Show
1 older comment
Brett Shoelson
on 11 May 2012
Nice, David!
Jon Agustsson
on 6 Jul 2012
Nice indeed.
I am surprised that it is more efficient to solve this with a recursive function than a while loop.
This solution has size 43:
while n(end) > 1
n = [n mod(n(end),2)*(n(end)*2.5+1) + n(end)/2];
end
Is the loop overhead greater than the recursion overhead? Or is the weak point having to go to n(end) at each iteration?
Jon Agustsson
on 6 Jul 2012
Strange I can not delete my first comment. I wanted to format it a bit nicer :)
Chien
on 14 Aug 2013
Good solution, David!:)
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!