How to resolve the algorithm Disarium numbers step by step in the SETL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Disarium numbers step by step in the SETL programming language
Table of Contents
Problem Statement
A Disarium number is an integer where the sum of each digit raised to the power of its position in the number, is equal to the number.
135 is a Disarium number: 11 + 32 + 53 == 1 + 9 + 125 == 135 There are a finite number of Disarium numbers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Disarium numbers step by step in the SETL programming language
Source code in the setl programming language
program disarium_numbers;
loop for n in [0..2700000] | disarium n do
print(n);
end loop;
op disarium(n);
k := n;
digits := [[k mod 10, k div:= 10](1) : until k=0];
p := #digits+1;
powsum := +/[d ** (p -:= 1) : d in digits];
return powsum = n;
end op;
end program;
You may also check:How to resolve the algorithm Sudoku step by step in the J programming language
You may also check:How to resolve the algorithm Password generator step by step in the VBA programming language
You may also check:How to resolve the algorithm Currying step by step in the Logtalk programming language
You may also check:How to resolve the algorithm HTTP step by step in the Lua programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Forth programming language