How to resolve the algorithm Super-d numbers step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Super-d numbers step by step in the jq 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 jq programming language
Source code in the jq programming language
# To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
# Input is $d, the number of consecutive digits, 2 <= $d <= 9
# $max is the number of superd numbers to be emitted.
def superd($number):
. as $d
| tostring as $s
| ($s * $d) as $target
| {count:0, j: 3 }
| while ( .count <= $number;
.emit = null
| if ((.j|power($d) * $d) | tostring) | index($target)
then .count += 1
| .emit = .j
else .
end
| .j += 1 )
| select(.emit).emit ;
# super-d for 2 <=d < 8
range(2; 8)
| "First 10 super-\(.) numbers:",
superd(10)
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the Lua programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the Haskell programming language
You may also check:How to resolve the algorithm Visualize a tree step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Address of a variable step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Goldbach's comet step by step in the Mathematica/Wolfram Language programming language