Hello!
I'm calculating Fibonacci numbers and I want to count the number of digits for the nth. My code at the moment looks like this:
Fn being the nth Fib#Code:Fn = FnMinus1 + FnMinus2; DigitCount = columns(isdigit(int2str(Fn)));
My way is fairly longwinded (feel free to skip this paragraph if you know your stuff): 'int2str' converts it to a string, 'isdigit' creates a row vector with 1 for every digit (i.e. 012345678 or 9) in a different column. Then 'columns' counts the number of columns.
This works fine for 3/4/5 digits but Octave goes dead when I ask it to count 1000 digits. I think it's probably my chain of functions that's slowing me down. Anyone know a better way of doing it?
It is for a Project Euler problem.
Bookmarks