How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the jq programming language

Published on 12 May 2024 09:40 PM
#Jq

How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the jq programming language

Table of Contents

Problem Statement

Generate the sequence a(n) when each element is the minimum integer multiple m such that the digit sum of n times m is equal to n.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the jq programming language

Source code in the jq programming language

1 | until((. * $n) | digitSum == $n; . + 1)

def minimum_integer_multiple:
  def digitSum:
    def add(s): reduce s as $_ (0; .+$_);
      add(tostring | explode[] | . - 48);

  . as $n
  | 1 | until((. * $n) | digitSum == $n; . + 1);

# This function assumes that nan can be taken as the eos marker
def nwise(stream; $n):
  foreach (stream, nan) as $x ([];
    if length == $n then [$x] else . + [$x] end)
  | if (.[-1] | isnan) and length>1 then .[:-1]
    elif length == $n then .
    else empty
    end;

def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;

nwise(
  range(1; 71) | minimum_integer_multiple;
  10)
| map(lpad(9)) | join(" ")

  

You may also check:How to resolve the algorithm Spiral matrix step by step in the PL/I programming language
You may also check:How to resolve the algorithm Null object step by step in the Ruby programming language
You may also check:How to resolve the algorithm Curzon numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Ring programming language
You may also check:How to resolve the algorithm Bioinformatics/base count step by step in the RPL programming language