

Definition

A factorion is a natural number that equals the sum of the factorials of its digits.



Example
 
145   is a factorion in base 10 because:


          1! + 4! + 5!   =   1 + 24 + 120   =   145 





It can be shown (see talk page) that no factorion in base 10 can exceed   1,499,999.



Task

Write a program in your language to demonstrate, by calculating and printing out the factorions, that:

   There are   3   factorions in base   9
   There are   4   factorions in base 10
   There are   5   factorions in base 11 
   There are   2   factorions in base 12     (up to the same upper bound as for base 10)


See also

 Wikipedia article
 OEIS:A014080 - Factorions in base 10
 OEIS:A193163 - Factorions in base n


/*REXX program calculates and displays   factorions   in  bases  nine ───► twelve.      */
parse arg LOb HIb lim .                          /*obtain optional arguments from the CL*/
if LOb=='' | LOb==","  then LOb=       9         /*Not specified?  Then use the default.*/
if HIb=='' | HIb==","  then HIb=      12         /* "      "         "   "   "      "   */
if lim=='' | lim==","  then lim= 1500000  -  1   /* "      "         "   "   "      "   */
 
  do fact=0  to HIb;   !.fact= !(fact)           /*use memoization for factorials.      */
  end   /*fact*/
 
  do base=LOb  to  HIb                           /*process all the required bases.      */
  @= 1 2                                         /*initialize the list  (@)  to  1 & 2. */
          do j=3  for lim-2;  $= 0               /*initialize the sum   ($)  to  zero.  */
                                          t= j   /*define the target  (for the sum !'s).*/
                                 do until t==0;    d= t // base      /*obtain a "digit".*/
                                                   $= $ + !.d        /*add  !(d) to sum.*/
                                                   t= t % base       /*get a new target.*/
                                 end   /*until*/
          if $==j  then @= @ j                   /*Good factorial sum? Then add to list.*/
          end   /*i*/
  say
  say 'The factorions for base '      right( base, length(HIb) )        " are: "         @
  end   /*base*/
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; parse arg x;  !=1;    do j=2  to x;  !=!*j;  end;   return !  /*factorials*/