The Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are
Write a MATLAB script that will give you G(n) when given n.
Efficiency is key here, since some of the values in the test suite will take a while to calculate.
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
4985 Solvers
2018 Solvers
Sort a list of complex numbers based on far they are from the origin.
3857 Solvers
Sum all integers from 1 to 2^n
6556 Solvers
Compute a dot product of two vectors x and y
653 Solvers