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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Super-d numbers step by step in the Wren 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 Wren programming language

Source code in the wren programming language

import "/big" for BigInt
import "/fmt" for Fmt

var start = System.clock
var rd = ["22", "333", "4444", "55555", "666666", "7777777", "88888888"]
for (i in 2..8) {
    Fmt.print("First 10 super-$d numbers:", i)
    var count = 0
    var j = BigInt.three
    while (true) {
        var k = j.pow(i) * i
        var ix = k.toString.indexOf(rd[i-2])
        if (ix >= 0) {
            count = count + 1
            Fmt.write("$i ", j)
            if (count == 10) {
                Fmt.print("\nfound in $f seconds\n", System.clock - start)
                break
            }
        }
        j = j.inc
    }
}

/* super-d_numbers_gmp.wren */

import "./gmp" for Mpz
import "./fmt" for Fmt
 
var start = System.clock
var rd = ["22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"]
for (i in 2..9) {
    Fmt.print("First 10 super-$d numbers:", i)
    var count = 0
    var j = Mpz.three
    var k = Mpz.new()
    while (true) {
        k.pow(j, i).mul(i)
        var ix = k.toString.indexOf(rd[i-2])
        if (ix >= 0) {
            count = count + 1
            Fmt.write("$i ", j)
            if (count == 10) {
                Fmt.print("\nfound in $f seconds\n", System.clock - start)
                break
            }
        }
        j.inc
    }
}

  

You may also check:How to resolve the algorithm Numerical integration step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Abundant odd numbers step by step in the Factor programming language
You may also check:How to resolve the algorithm De Bruijn sequences step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Ruby programming language
You may also check:How to resolve the algorithm Compiler/code generator step by step in the RATFOR programming language