How to resolve the algorithm Super-d numbers step by step in the Julia programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Super-d numbers step by step in the Julia programming language

Table of Contents

Problem Statement

A super-d number is a positive, decimal (base ten) integer   n   such that   d × nd   has at least   d   consecutive digits   d   where For instance, 753 is a super-3 number because 3 × 7533 = 1280873331.

Super-d   numbers are also shown on   MathWorld™   as   super-d   or   super-d.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Super-d numbers step by step in the Julia programming language

The provided Julia code defines a function superd that calculates and prints the first 10 "super-$N" numbers for a given integer N. A super-$N$ number is a positive integer that, when raised to the power of N, ends in exactly N copies of the digit N.

The code starts by printing a header to indicate that it will display the first 10 super-$N$ numbers. It then initializes two variables: count, which keeps track of the number of super-$N$ numbers found so far, and j, which is the starting integer to check.

The code sets target to a string of N copies of the character N. This is the desired ending string that the super-$N$ number should have when raised to the power of N. The code then enters a while loop, which continues until count reaches 10.

Inside the loop, the code checks if the string representation of j^N * N contains the target string target using the occursin function. If it does, it means that j is a super-$N$ number, and the code prints it and increments count. After that, it increments j to check the next integer.

After the loop completes, the function prints a newline character to separate the results. The code then calls the superd function for N values ranging from 2 to 9 and times the execution using the @time macro to measure the performance for each N.

Source code in the julia programming language

function superd(N)
    println("First 10 super-$N numbers:")
    count, j = 0, BigInt(3)
    target = Char('0' + N)^N
    while count < 10
        if occursin(target, string(j^N * N))
            count += 1
            print("$j ")
        end
        j += 1
    end
    println()
end

for n in 2:9
    @time superd(n)
end


  

You may also check:How to resolve the algorithm Averages/Mode step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Vampire number step by step in the Swift programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the Logo programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the Pure Data programming language
You may also check:How to resolve the algorithm Sphenic numbers step by step in the C programming language