How to resolve the algorithm Rare numbers step by step in the Ring programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Rare numbers step by step in the Ring programming language

Table of Contents

Problem Statement

Rare   numbers are positive integers   n   where:

Show all output here, on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Rare numbers step by step in the Ring programming language

Source code in the ring programming language

load "stdlib.ring"

see "working..." + nl
see "the first 5 rare numbers are:" + nl

num = 0

for n = 1 to 2042832002
    strn = string(n)
    nrev = ""
    for m = len(strn) to 1 step -1
        nrev = nrev + strn[m]
    next
    nrev = number(nrev)
    sum = n + nrev
    diff = n - nrev
    if diff < 1
       loop    
    ok
    sqrtsum = sqrt(sum)
    flagsum = (sqrtsum = floor(sqrtsum))
    sqrtdiff = sqrt(diff)
    flagdiff= (sqrtdiff = floor(sqrtdiff))
    if flagsum = 1 and flagdiff = 1
       num = num + 1
       see "" + num + ": " + n + nl
    ok
next
see "done..." + nl

  

You may also check:How to resolve the algorithm URL encoding step by step in the Perl programming language
You may also check:How to resolve the algorithm Search a list step by step in the C# programming language
You may also check:How to resolve the algorithm Knight's tour step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Multi-base primes step by step in the Perl programming language
You may also check:How to resolve the algorithm Special characters step by step in the AWK programming language