###Introduction
Let's observe the following sequence (non-negative integers):
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...
For example, let's take the first three numbers. These are 0, 1, 2
. The numbers used in this sequence can be ordered in six different ways:
012 120
021 201
102 210
So, let's say that F(3) = 6. Another example is F(12). This contains the numbers:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Or the concatenated version:
01234567891011
To find the number of ways to rearrange this, we first need to look at the length of this string. The length of this string is 14
. So we compute 14!. However, for example the ones can exchange places without disrupting the final string. There are 2 zeroes, so there are 2! ways to exhange the zeroes without disrupting the order. There are also 4 ones, so there are 4! ways to switch the ones. We divide the total by these two numbers:
This has 14! / (4! × 2!) = 1816214400 ways to arrange the string 01234567891011
. So we can conclude that F(12) = 1816214400.
###The task
Given N, output F(N). For the ones who don't need the introduction. To compute F(N), we first concatenate the first N non-negative integers (e.g. for N = 12, the concatenated string would be 01234567891011
) and calculate the number of ways to arrange this string.
###Test cases
Input: Output:
0 1
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800
11 119750400
12 1816214400
13 43589145600
14 1111523212800
15 30169915776000
###Note
Computing the answer must be computed within a time limit of 10 seconds, brute-forcing is disallowed. Languages using 32 bit integers must handle the test-cases up to 11, but must theoretically work for all of them (when given unlimited memory).
This is code-golf, so the submission with the least amount of bytes wins!