I prefer g(end+1:end+g(gptr))=gptr; to usage of repmat. My machine to solve 1234567 takes 48msec vs 15.4 sec using repmat. repmat has a performance issue with large column replication. Unfortunately score is code size and not time.
totally agree (not to mention the entire 'growing inside a loop' uglyness), cody style is very far from any reasonable coding standard...
That's very interesting. The time difference on my (presumably much older) version of MATLAB is much less. Your method gives me an average time of about 18.8 sec, while repmat gives me an average time of 19.5 sec.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
assert(isequal(euler341(1),1))
|
2 | Pass |
%%
assert(isequal(euler341(10),5))
|
3 | Pass |
%%
assert(isequal(euler341(310),42))
|
4 | Pass |
%%
assert(isequal(euler341(4242),210))
|
5 | Pass |
%%
assert(isequal(euler341(328509),3084))
|
6 | Pass |
%%
assert(isequal(euler341(551368),4247))
|
7 | Pass |
%%
assert(isequal(euler341(614125),4540))
|
Count from 0 to N^M in base N.
220 Solvers
1143 Solvers
Get the elements of diagonal and antidiagonal for any m-by-n matrix
267 Solvers
331 Solvers
2455 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!