Groovy web console

subscribe to the feed Subscribe
to this
site

Rearranging the sequence

Published 7 years ago by lealand
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def f(n){def s=(0..n-1).join('')
0==n?1:g(s.size())/s.inject([:]){a,i->a[i]=a[i]?a[i]+1:1;a}*.value.inject(1){a,i->a*g(i)}}
BigInteger g(n){n<=1?1:n*g(n-1)}

// Testing
(16).times { println ("$it: ${f it}") }