How to resolve the algorithm Factorions step by step in the Lambdatalk programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factorions step by step in the Lambdatalk programming language

Table of Contents

Problem Statement

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

145   is a factorion in base 10 because:

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

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Factorions step by step in the Lambdatalk programming language

Source code in the lambdatalk programming language

{def facts
 {S.first
  {S.map {{lambda {:a :i} 
                  {A.addlast! {* {A.get {- :i 1} :a} :i} :a}
          } {A.new 1}}
         {S.serie 1 11}}}}
-> facts

{def sumfacts
 {def sumfacts.r
  {lambda {:base :sum :i}
   {if {> :i 0}
    then {sumfacts.r :base
                     {+ :sum {A.get {% :i :base} {facts}}}
                     {floor {/ :i :base}}}
    else :sum }}}
 {lambda {:base :n}
  {sumfacts.r :base 0 :n}}} 
-> sumfacts

{def show
 {lambda {:base}
  {S.replace \s by space in
   {S.map {{lambda {:base :i}
                   {if {= {sumfacts :base :i} :i} then :i else}
           } :base}
          {S.serie 1 50000}}}}}
-> show

{S.map {lambda {:base}
               {div}factorions for base :base: {show :base}} 
       9 10 11 12}
->
factorions for base 9: 1 2 41282 
factorions for base 10: 1 2 145 40585 
factorions for base 11: 1 2 26 48 40472 
factorions for base 12: 1 2


  

You may also check:How to resolve the algorithm Collections step by step in the Fancy programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the AWK programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the MANOOL programming language
You may also check:How to resolve the algorithm Comments step by step in the Tiny BASIC programming language
You may also check:How to resolve the algorithm Box the compass step by step in the QBasic programming language