decimalToFactorial

This function transforms decimal value into a value in the factorial number system stored in fac.

A factorial number is constructed as: fac[0] * 0! + fac[1] * 1! + ... fac[20] * 20!

@safe pure nothrow @nogc
size_t
decimalToFactorial
(
ulong decimal
,
ref ubyte[21] fac
)

Parameters

decimal ulong

The decimal value to convert into the factorial number system.

fac ubyte[21]

The array to store the factorial number. The array is of size 21 as ulong.max requires 21 digits in the factorial number system.

Return Value

Type: size_t

A variable storing the number of digits of the factorial number stored in fac.

Examples

ubyte[21] fac;
size_t idx = decimalToFactorial(2982, fac);

assert(fac[0] == 4);
assert(fac[1] == 0);
assert(fac[2] == 4);
assert(fac[3] == 1);
assert(fac[4] == 0);
assert(fac[5] == 0);
assert(fac[6] == 0);

Meta