This is a shamless answer,I admit...But the explicit recurrence relation is insanely slow,hope to see you guys solve this problem more efficient.
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.
May you give a short explanation on this solution?
This is the asymptotic expression of nth term based on the golden ratio. See http://en.wikipedia.org/wiki/Golomb_sequence
High school cafeteria
Project Euler: Problem 2, Sum of even Fibonacci
Create logical matrix with a specific row and column sums
Magic is simple (for beginners)
Circular Primes (based on Project Euler, problem 35)
It's going down. We're finding simbers!
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
Why the heck are they blinking!?!?
Longest run of consecutive numbers
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office