最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

permutation - What function calculates the value of an identity index on n items in base n? - Stack Overflow

programmeradmin3浏览0评论

Given an increasing identity index on n items [ 0, 1, ..., n-1 ], a value can be calculated by considering each entry as a number in base n and with place value corresponding to it's location (powers of n, right-to-left).

For increasing n I calculate:

2 -> [0,1] -> 1
3 -> [0,1,2] -> (1.3 + 2) = 5
4 -> [0,1,2,3] -> (1.4^2 + 2.4 + 3) = 27
5 -> [0,1,2,3,4] -> (1.5^3 + 2.5^2 + 3.5 + 4) = 194
6 -> [0,1,2,3,4,5] -> (1.6^4 + 2.6^3 + 3.6^2 + 4.6 + 5) = 1865

It's fairly easy to calculate these numbers by brute force, but is there a nice function that provides the same result?

I'm interested in the permutations of an identity index and how they're distributed within the space of the base box (i.e. the calculation above), since they must produce select values between 0 and (nn - 1).

I can already express (and code) the function as a summation.

发布评论

评论列表(0)

  1. 暂无评论