A colorful number is a non-negative base 10 integer where the product of every sub group of consecutive digits is unique.



E.G.
24753 is a colorful number. 2, 4, 7, 5, 3, (2×4)8, (4×7)28, (7×5)35, (5×3)15, (2×4×7)56, (4×7×5)140, (7×5×3)105, (2×4×7×5)280, (4×7×5×3)420, (2×4×7×5×3)840

Every product is unique.



2346 is not a colorful number. 2, 3, 4, 6, (2×3)6, (3×4)12, (4×6)24, (2×3×4)48, (3×4×6)72, (2×3×4×6)144

The product 6 is repeated.



Single digit numbers are considered to be colorful. A colorful number larger than 9 cannot contain a repeated digit, the digit 0 or the digit 1. As a consequence, there is a firm upper limit for colorful numbers; no colorful number can have more than 8 digits.



Task
 Write a routine (subroutine, function, procedure, whatever it may be called in your language) to test if a number is a colorful number or not.
 Use that routine to find all of the colorful numbers less than 100.
 Use that routine to find the largest possible colorful number.


Stretch
 Find and display the count of colorful numbers in each order of magnitude.
 Find and show the total count of all colorful numbers.

Colorful numbers have no real number theory application. They are more a recreational math puzzle than a useful tool.

func IPow(A, B);        \A^B
int  A, B, T, I;
[T:= 1;
for I:= 1 to B do T:= T*A;
return T;
];
 
func Colorful(N);       \Return 'true' if N is a colorful number
int  N, Digits, R, I, J, Prod;
def  Size = 9*8*7*6*5*4*3*2 + 1;
char Used(Size), Num(10);
[if N < 10 then return true;    \single digit number is colorful
FillMem(Used, false, 10);       \digits must be unique
Digits:= 0;
repeat  N:= N/10;               \slice digits off N
        R:= rem(0);
        if N=1 or R=0 or R=1 then return false;
        if Used(R) then return false;
        Used(R):= true;         \digits must be unique
        Num(Digits):= R;
        Digits:= Digits+1;
until   N = 0;
FillMem(Used+10, false, Size-10); \products must be unique
for I:= 0 to Digits-2 do
    [Prod:= Num(I);
    for J:= I+1 to Digits-1 do
        [Prod:= Prod * Num(J);
        if Used(Prod) then return false;
        Used(Prod):= true;
        ];
    ];
return true;
];
 
int Count, N, Power, Total;
[Text(0, "Colorful numbers less than 100:
");
Count:= 0;
for N:= 0 to 99 do
    if Colorful(N) then
        [IntOut(0, N);
        Count:= Count+1;
        if rem(Count/10) then ChOut(0, 9\tab\) else CrLf(0);
        ];
Text(0, "
 
Largest magnitude colorful number: ");
N:= 98_765_432;
loop    [if Colorful(N) then quit;
        N:= N-1;
        ];
IntOut(0, N);
Text(0, "
 
Count of colorful numbers for each order of magnitude:
");
Total:= 0;
for Power:= 1 to 8 do
    [Count:= if Power=1 then 1 else 0;
    for N:= IPow(10, Power-1) to IPow(10, Power)-1 do
        if Colorful(N) then Count:= Count+1;
    IntOut(0, Power);
    Text(0, " digit colorful number count: ");
    IntOut(0, Count);
    CrLf(0);
    Total:= Total + Count;
    ];
Text(0, "
Total colorful numbers: ");
IntOut(0, Total);
CrLf(0);
]