How to resolve the algorithm Disarium numbers step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Disarium numbers step by step in the Nim 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 Nim programming language
Source code in the nim programming language
import strutils
import math
proc is_disarium(num: int): bool =
let n = intToStr(num)
var sum = 0
for i in 0..len(n)-1:
sum += int((int(n[i])-48) ^ (i+1))
return sum == num
var i = 0
var count = 0
while count < 19:
if is_disarium(i):
stdout.write i, " "
count += 1
i += 1
echo ""
You may also check:How to resolve the algorithm Compare length of two strings step by step in the Ada programming language
You may also check:How to resolve the algorithm Optional parameters step by step in the C++ programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Modula-2 programming language
You may also check:How to resolve the algorithm Program name step by step in the PowerBASIC programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the Sidef programming language