I decided to share this awk code to compute s(n), primarily because I like that it uses only addition and the distributive law, and not factoring, to compute s(n). It also uses a bit of string processing and hash-table look up, but is a nice example of the use of associative arrays. I also like it because it uses O(\pi(n)*log(n))$O(\pi(n)\log(n))$ bytes of memory, essentially one entry per prime number less than n. Apologies to sleepless in beantown: I prefer obfuscated awk and nice algorithms to one-liners in Perl, so do not accept his challenge made in a comment on his answer.
BEGIN{ LIM = 10000 ; SEP = "," prev = count[1] = count[2] = count[3] = SENTINEL = 0 dir[1] = 1 ; dir[2] = 0 ; dir[3] = -1 str[1] = " / at " ; str[2] = " = at " ; str[3] = " \\\\\\ at " notify[1] = notify[3] = 3; notify[2] = 6 for( n = 2 ; n notify[k]) print count[k] str[k] n ":" s } prev = s } }
Sample output verifies the results of sleepless in beantown, plus shows that there are long runs where s is constant: 2=s(2302)=...=s(2308) . It suggests that there is a function f(s) such that there are at most f(s) consecutive numbers with value s. I suspect f(1)=4, but do not yet have a proof.
Gerhard "Ask Me About System Design" Paseman, 2010.12.29