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))
|
Find common elements in matrix rows
1232 Solvers
190 Solvers
Sum the numbers on the main diagonal
453 Solvers
Integer sequence - 2 : Kolakoski sequence
105 Solvers
Is this is a Tic Tac Toe X Win?
438 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!