How to resolve the algorithm Smith numbers step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Smith numbers step by step in the Action! programming language
Table of Contents
Problem Statement
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as joke numbers.
Using the number 166 Find the prime factors of 166 which are: 2 x 83 Then, take those two prime factors and sum all their decimal digits: 2 + 8 + 3 which is 13 Then, take the decimal digits of 166 and add their decimal digits: 1 + 6 + 6 which is 13 Therefore, the number 166 is a Smith number.
Write a program to find all Smith numbers below 10000.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Smith numbers step by step in the Action! programming language
Source code in the action! programming language
CARD FUNC SumDigits(CARD n)
CARD res,a
res=0
WHILE n#0
DO
res==+n MOD 10
n==/10
OD
RETURN (res)
CARD FUNC PrimeFactors(CARD n CARD ARRAY f)
CARD a,count
a=2 count=0
DO
IF n MOD a=0 THEN
f(count)=a
count==+1
n==/a
IF n=1 THEN
RETURN (count)
FI
ELSE
a==+1
FI
OD
RETURN (0)
PROC Main()
CARD n,i,s1,s2,count,tmp
CARD ARRAY f(100)
FOR n=4 TO 10000
DO
count=PrimeFactors(n,f)
IF count>=2 THEN
s1=SumDigits(n)
s2=0
FOR i=0 TO count-1
DO
tmp=f(i)
s2==+SumDigits(tmp)
OD
IF s1=s2 THEN
PrintC(n) Put(32)
FI
FI
Poke(77,0) ;turn off the attract mode
OD
RETURN
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the ScratchScript programming language
You may also check:How to resolve the algorithm Combinations and permutations step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Permutations step by step in the Maxima programming language
You may also check:How to resolve the algorithm Machine code step by step in the Commodore BASIC programming language
You may also check:How to resolve the algorithm SHA-1 step by step in the Emacs Lisp programming language