Minimum multiple of m where digital sum equals m: Difference between revisions

Add ABC
m (→‎much faster: coupla comment tweaks)
(Add ABC)
 
(27 intermediate revisions by 17 users not shown)
Line 1:
{{draft task}}
 
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'''.
Line 21:
 
 
 
=={{header|11l}}==
{{trans|C++}}
 
<syntaxhighlight lang="11l">
F digit_sum(=n)
V sum = 0
L n > 0
sum += n % 10
n I/= 10
R sum
 
L(n) 1..70
L(m) 1..
I digit_sum(m * n) == n
print(‘#8’.format(m), end' I n % 10 == 0 {"\n"} E ‘ ’)
L.break
</syntaxhighlight>
 
{{out}}
<pre>
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # find the smallest m where mn = digit sum of n, n in 1 .. 70 #
# returns the digit sum of n, n must be >= 0 #
OP DIGITSUM = ( INT n )INT:
Line 47 ⟶ 76:
OD
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 59 ⟶ 88:
</pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="ABC">HOW TO RETURN digit.sum n:
PUT 0 IN sum
WHILE n>0:
PUT sum + (n mod 10) IN sum
PUT floor (n/10) IN n
RETURN sum
 
HOW TO RETURN a131382 n:
PUT 1 IN m
WHILE n <> digit.sum (m*n): PUT m+1 IN m
RETURN m
 
FOR n IN {1..70}:
WRITE (a131382 n)>>9
IF n mod 10=0: WRITE /</syntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">{n←⍵ ⋄ (+∘1)⍣{n=+/10⊥⍣¯1⊢⍺×n}⊢0 } ¨ 7 10⍴⍳70</langsyntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
Line 71 ⟶ 124:
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MINIMUM_MULTIPLE_OF_M_WHERE_DIGITAL_SUM_EQUALS_M.AWK
BEGIN {
Line 95 ⟶ 149:
return(s)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 110 ⟶ 164:
=={{header|BASIC}}==
==={{header|BASIC256}}===
<langsyntaxhighlight BASIC256lang="basic256">c = 0
n = 1
while c < 70
Line 129 ⟶ 183:
n += 1
end while
end</langsyntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|BBC BASIC}}===
{{trans|C}}
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> FOR N%=1 TO 70
PRINT FNa131382(N%);
IF N% MOD 10 == 0 PRINT
NEXT
END
 
DEF FNa131382(n%) LOCAL m%
m%=1
WHILE n% <> FNdigit_sum(m% * n%)
m%+=1
ENDWHILE
=m%
 
DEF FNdigit_sum(n%) LOCAL sum%
WHILE n%
sum%+=n% MOD 10
n%/=10
ENDWHILE
=sum%</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">100 cls
110 c = 0
120 n = 1
130 while c < 70
140 m = 1
150 while 1
160 nm = n*m
170 t = 0
180 while nm
190 t = t + nm mod 10
200 nm = floor(nm / 10)
210 wend
220 if t = n then exit while
230 m = m +1
240 wend
260 c = c +1
270 print using "########"; m;
280 if c mod 10 = 0 then print
290 n = n +1
300 wend
310 end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|FreeBASIC}}===
{{trans|Phix}}
<langsyntaxhighlight lang="freebasic">#define floor(x) ((x*2.0-0.5) Shr 1)
 
Dim As Integer c = 0, n = 1
Line 156 ⟶ 256:
n += 1
Loop
Sleep</syntaxhighlight>
</lang>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
Line 166 ⟶ 265:
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim c As Integer = 0, n As Integer = 1
 
Do While c < 70
Dim m As Integer = 1
Do
Dim nm As Integer = n * m, t As Integer = 0
While nm
t += nm Mod 10
nm = Floor(nm / 10)
Wend
If t = n Then Break
m += 1
Loop
c += 1
Print Format(m, "######## ");
If c Mod 10 = 0 Then Print
n += 1
Loop
 
End</syntaxhighlight>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="PureBasic">Procedure.i floor(n.d)
Result = (n*2.0-0.5)
ProcedureReturn Result >> 1
EndProcedure
 
OpenConsole()
 
c.i = 0
n.i = 1
While c < 70
m.i = 1
Repeat
nm.d = n*m
t.d = 0
While nm
t = t + Mod(nm, 10)
nm = floor(nm/10)
Wend
If t = n
Break
EndIf
m + 1
ForEver
c + 1
Print(RSet(Str(m), 8) + " ")
If Mod(c, 10) = 0
PrintN("")
EndIf
n + 1
Wend
 
Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|True BASIC}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">LET c = 0
LET n = 1
 
DO WHILE c < 70
LET m = 1
DO
LET nm = n*m
LET t = 0
DO WHILE nm<>0
LET t = t+REMAINDER(nm,10)
LET nm = IP(nm/10)
LOOP
IF t = n THEN EXIT DO
LET m = m+1
LOOP
LET c = c+1
PRINT USING "######## ": m;
IF REMAINDER(c,10) = 0 THEN PRINT
LET n = n+1
LOOP
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "program name"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
c = 0
n = 1
DO WHILE c < 70
m = 1
DO WHILE 1
nm = n * m
t = 0
DO WHILE nm
t = t + nm MOD 10
nm = INT((nm / 10)+.5)
LOOP
IF t = n THEN EXIT DO
INC m
LOOP
INC c
PRINT FORMAT$("######## ", m);
IF c MOD 10 = 0 THEN PRINT
INC n
LOOP
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
<langsyntaxhighlight lang="yabasic">c = 0
n = 1
while c < 70
Line 187 ⟶ 402:
n = n + 1
wend
end</langsyntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
unsigned digit_sum(unsigned n) {
Line 216 ⟶ 429:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
Line 227 ⟶ 440:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
 
Line 246 ⟶ 459:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 260 ⟶ 473:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">digit_sum = proc (n: int) returns (int)
sum: int := 0
while n > 0 do
Line 291 ⟶ 504:
if n // 10 = 0 then stream$putl(po, "") end
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
Line 302 ⟶ 515:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. A131382.
Line 343 ⟶ 556:
ADD-DIGIT.
ADD DIGITS(D) TO DIGITSUM.</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>A( 1) = 1
Line 387 ⟶ 600:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub digit_sum(n: uint32): (sum: uint8) is
Line 411 ⟶ 624:
end if;
n := n + 1;
end loop;</langsyntaxhighlight>
{{out}}
<pre>1 1 1 1 1 1 1 1 1 19
Line 422 ⟶ 635:
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">/* this is very slow even in emulation - if you're going to try it
* on a real 8-bit micro I'd recommend setting this back to 40;
* it does, however, eventually get there */
Line 455 ⟶ 668:
if (n & 7) = 0 then writeln() fi
od
corp</langsyntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1
Line 466 ⟶ 679:
103507 154981 150661 1333333 163918 322579 315873 937342
1076923 1030303 880597 1469116 1157971 12842857</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
function SumDigits(N: integer): integer;
{Sum the integers in a number}
var T: integer;
begin
Result:=0;
repeat
begin
T:=N mod 10;
N:=N div 10;
Result:=Result+T;
end
until N<1;
end;
 
 
procedure MinimumMultipleM(Memo: TMemo);
{Find N's where DigitSum(N X M) = N.}
var N,M: integer;
var S: string;
begin
S:='';
for N:=1 to 70 do
for M:=1 to High(integer) do
begin
if SumDigits(M * N) = N then
begin
S:=S+Format('%8d',[M]);
if N mod 10 = 0 then S:=S+#$0D#$0A;
break;
end;
end;
Memo.Lines.Add(S);
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 115797112842857
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc f n .
m = 1
repeat
h = m * n
sum = 0
while h > 0
sum += h mod 10
h = h div 10
.
until sum = n
m += 1
.
return m
.
for n = 1 to 70
write f n & " "
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Minimum multiple of m where digital sum equals m. Nigel Galloway: January 31st., 2022
let SoD n=let rec SoD n=function 0L->int n |g->SoD(n+g%10L)(g/10L) in SoD 0L n
Line 477 ⟶ 764:
fN ((((pown 10L (g/9))-1L)+int64(g%9)*(pown 10L (g/9)))/int64 g)
Seq.initInfinite((+)1>>A131382)|>Seq.take 70|>Seq.chunkBySize 10|>Seq.iter(fun n->n|>Seq.iter(printf "%13d "); printfn "")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 488 ⟶ 775:
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|FOCAL}}==
<langsyntaxhighlight lang="focal">01.10 F N=1,40;D 2
01.20 Q
 
Line 503 ⟶ 791:
03.30 S S=S+(D-E*10)
03.40 S D=E
03.50 I (-D)3.2</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>N= 1 M= 1
Line 549 ⟶ 837:
=={{header|Forth}}==
{{works with|Gforth}}
<langsyntaxhighlight lang="forth">: digit-sum ( u -- u )
dup 10 < if exit then
10 /mod recurse + ;
Line 563 ⟶ 851:
 
70 main
bye</langsyntaxhighlight>
 
{{out}}
Line 574 ⟶ 862:
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|Go}}==
{{libheader|Go-rcu}}
<syntaxhighlight lang="go">package main
 
import "rcu"
 
func main() {
var res []int
for n := 1; n <= 70; n++ {
m := 1
for rcu.DigitSum(m*n, 10) != n {
m++
}
res = append(res, m)
}
rcu.PrintTable(res, 7, 10, true)
}</syntaxhighlight>
 
{{out}}
<pre>
1 1 1 1 1 1 1
1 1 19 19 4 19 19
13 28 28 11 46 199 19
109 73 37 199 73 37 271
172 1,333 289 559 1,303 847 1,657
833 1,027 1,576 1,282 17,497 4,339 2,119
2,323 10,909 11,111 12,826 14,617 14,581 16,102
199,999 17,449 38,269 56,413 37,037 1,108,909 142,498
103,507 154,981 150,661 1,333,333 163,918 322,579 315,873
937,342 1,076,923 1,030,303 880,597 1,469,116 1,157,971 12,842,857
</pre>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Bifunctor (first)
import Data.List (elemIndex, intercalate, transpose)
import Data.List.Split (chunksOf)
Line 608 ⟶ 928:
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</langsyntaxhighlight>
{{Out}}
<pre> 1 1 1 1 1 1 1 1 1 19
Line 619 ⟶ 939:
Implementation:
 
<syntaxhighlight lang="j">
<lang J>
findfirst=: {{
($:@((+1+i.@+:)@#)@[`(+&{. I.)@.(1 e. ]) u) ,1
Line 626 ⟶ 946:
A131382=: {{y&{{x = sumdigits x*y}} findfirst}}"0
 
sumdigits=: +/@|:@(10&#.inv)</langsyntaxhighlight>
 
Task example:
<langsyntaxhighlight Jlang="j"> A131382 1+i.4 10
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497</langsyntaxhighlight>
 
Stretch example:
<langsyntaxhighlight Jlang="j"> A131382 41+i.3 10
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</langsyntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang ="java">
public final class MinimumMultipleDigitSum {
 
public static void main(String[] aArgs) {
for ( int n = 1; n <= 70; n++ ) {
int k = 0;
while ( digitSum(k += n) != n );
System.out.print(String.format("%8d%s", k / n, ( n % 10 ) == 0 ? "\n" : " "));
}
}
private static int digitSum(int aN) {
int sum = 0;
while ( aN > 0 ) {
sum += aN % 10;
aN /= 10;
}
return sum;
}
 
}
</syntaxhighlight>
{{ out }}
<pre>
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|Jakt}}==
Output format follows the C++ solution with a small difference in the leading whitespace.
 
<syntaxhighlight lang="jakt">
fn digital_sum(anon n: i64, accumulator: i64 = 0) -> i64 => match n {
0 => accumulator
else => digital_sum(n: n / 10, accumulator: accumulator + n % 10)
}
 
fn main() {
for n in 1..71 {
for m in (1..) {
if digital_sum(n * m) == n {
print("{: 9}", m)
if n % 10 == 0 {
println()
}
break
}
}
}
}
</syntaxhighlight>
{{out}}
<pre>
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with jq and gojq, the C and Go implementations of jq'''
 
Apart from a small tweak to the `lpad` function, the following program also works with jaq, the Rust
implementation of jq.
 
Assuming `digitSum` has been suitably defined to yield
the sum of the digits of a decimal number,
a jq expression for computing the $nth-term in the series is:
<syntaxhighlight lang=jq>
1 | until((. * $n) | digitSum == $n; . + 1)
</syntaxhighlight>
 
Let's abstract that into a self-contained jq function:
<syntaxhighlight lang=jq>
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);
</syntaxhighlight>
 
To display the first several values of the series in rows of 10 values,
we could first capture them as a single array, but to
avoid allocating unnecessary memory and to highlight jq's support for
stream-oriented processing,
we shall instead use the following function for grouping
the items in a (possibly non-finite) stream into arrays of
length at most $max:
<syntaxhighlight lang=jq>
# 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;
</syntaxhighlight>
 
The tasks can then be accomplished as follows:
<syntaxhighlight lang=jq>
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
nwise(
range(1; 71) | minimum_integer_multiple;
10)
| map(lpad(9)) | join(" ")
</syntaxhighlight>
{{output}}
<pre>
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">minproddigsum(n) = findfirst(i -> sum(digits(n * i)) == n, 1:typemax(Int32))
 
for j in 1:70
print(lpad(minproddigsum(j), 10), j % 7 == 0 ? "\n" : "")
end
</langsyntaxhighlight>{{out}}
<pre>
1 1 1 1 1 1 1
Line 662 ⟶ 1,113:
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
VECTOR VALUES FMT = $2HA(,I2,4H) = ,I8*$
Line 679 ⟶ 1,130:
TRANSFER TO DIGIT
END OF FUNCTION
END OF PROGRAM</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>A( 1) = 1
Line 751 ⟶ 1,202:
A(69) = 1157971
A(70) = 12842857</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/strutils
 
func digitSum(n: Natural): int =
## Return the sum of digits of "n".
var n = n
while n != 0:
result.inc n mod 10
n = n div 10
 
iterator a131382(count: Natural): (int, int) =
## Yield the index and value of the first "count" elements
## of the sequence.
for n in 1..count:
var m = 1
while digitSum(m * n) != n:
inc m
yield (n, m)
 
for idx, n in a131382(70):
stdout.write align($n, 9)
if idx mod 10 == 0: stdout.write '\n'
</syntaxhighlight>
 
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857
</pre>
 
=={{header|Pascal}}==
Line 757 ⟶ 1,242:
Constructing minimal start number with sum of digits = m -> k+9+9+9+9+9+9 <BR>
Break up in parts of 4 digits.Could be more optimized.
<langsyntaxhighlight lang="pascal">program m_by_n_sumofdgts_m;
//Like https://oeis.org/A131382/b131382.txt
{$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$ENDIF}
Line 982 ⟶ 1,467:
writeln('Total runtime ',GetTickCount64-T0,' ms');
{$IFDEF WINDOWS} readln{$ENDIF}
end.</langsyntaxhighlight>
{{out|@TIO.RUN}}
<pre>
Line 1,051 ⟶ 1,536:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Minimum_multiple_of_m_where_digital_sum_equals_m
Line 1,063 ⟶ 1,548:
$m;
} 1 .. 70;
print "@answers\n\n" =~ s/.{65}\K /\n/gr;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,076 ⟶ 1,561:
=={{header|Phix}}==
{{trans|XPL0}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
Line 1,094 ⟶ 1,579:
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,107 ⟶ 1,592:
===much faster===
<small>(Not that the above is particularly slow, but you certainly wouldn't want to push it much past 70)</small>
{{libheader|Phix/online}}
<!--<lang Phix>(phixonline)-->
You can run this online [http://phix.x10.mx/p2js/mmnn.htm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\mmnn.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 1,463 ⟶ 1,950:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n1,000,000: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mmnn</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e6</span><span style="color: #0000FF;">))})</span> <span style="color: #000080;font-style:italic;">-- (0.0s)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,536 ⟶ 2,023:
366: 270491803278688524590163934425956284153 272479564032425067847411444141689373297 1086956521739130163043478260869565217391 1027100271002710027100271002710027100271
"2 minutes and 29s"
</pre>
===much simpler, to 1000===
Uses dynamic programming, at least I think it does.
Maintains a grid of digit sum against remainder in the form of the (final) digit that got us there first (so it's the smallest) along with a (parent) link to the chain of preceding digits. In effect, we are simply performing a breadth first search of unvisited nodes to get from {0,0} aka "" to {n,0} ie a digital sum of n with no remainder. The clever (ok, obvious if you prefer) maths bit is remainder(<parent's remainder>*10,n) when appending each individual digit.
 
While a fair bit slower on most individual numbers (esp under pwa/p2js) it hits far fewer bottlenecks such as that 275 above, and at least past 200 turns out to be quite a bit faster. However there is no equivalent trailing zero optimisation that I can see, and it caps out at 1e4 on 32 bit, 2e4 on 64 bit, for obvious reasons the square root of the hard limits of the above (assuming a number the code above doesn't pick a fight with).<br>
Translation of the C++ code on [[oeis:A002998|A002998]] but with the additional final divide for [[oeis:A131382|A131382]] and significantly clearer imnsho.
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- (for the final divide only)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">mmnn</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #008000;">"0"</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #000080;font-style:italic;">-- (edge case)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">digits</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)),</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"0"</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">parent</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)),</span> <span style="color: #000000;">queue</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">dsum</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">residue</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pdx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (found or queue not empty at end of loop)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">dsum</span><span style="color: #0000FF;">></span><span style="color: #000000;">n</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">dsum</span><span style="color: #0000FF;">=</span><span style="color: #000000;">n</span> <span style="color: #008080;">and</span> <span style="color: #000000;">residue</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- success!!</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'0'</span><span style="color: #0000FF;">+</span><span style="color: #000000;">digit</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">pdx</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">pdx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">res</span>
<span style="color: #000000;">pdx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">parent</span><span style="color: #0000FF;">[</span><span style="color: #000000;">pdx</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #004080;">mpz</span> <span style="color: #000000;">z</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_init</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">mpz_fdiv_q_ui</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">z</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_get_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">drx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dsum</span><span style="color: #0000FF;">*</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">residue</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">drx</span><span style="color: #0000FF;">]=</span><span style="color: #008000;">' '</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">drx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'0'</span><span style="color: #0000FF;">+</span><span style="color: #000000;">digit</span>
<span style="color: #000000;">parent</span><span style="color: #0000FF;">[</span><span style="color: #000000;">drx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">pdx</span>
<span style="color: #000000;">queue</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">queue</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">dsum</span><span style="color: #0000FF;">,</span><span style="color: #000000;">residue</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">dsum</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">residue</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">residue</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">queue</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #008000;">"FAIL"</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">dsum</span><span style="color: #0000FF;">,</span><span style="color: #000000;">residue</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">queue</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">queue</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">queue</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span>
<span style="color: #000000;">pdx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dsum</span><span style="color: #0000FF;">*</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">residue</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
<span style="color: #000000;">residue</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">residue</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">return</span> <span style="color: #008000;">"what???"</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">llen</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">200</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- 1.2s (15.4s under pwa/p2js)
--for n=1 to 274 do -- 3.1s
--for n=1 to 369 do -- 7.1s
--for n=1 to 500 do -- 19s
--for n=1 to 1000 do -- 2 mins 29s</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">mmnn</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">llen</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">bool</span> <span style="color: #000000;">bCR</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">101</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">:</span><span style="color: #000000;">llen</span><span style="color: #0000FF;">></span><span style="color: #000000;">118</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">bCR</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n%3d:"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #000000;">llen</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">+</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %-11s"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<span style="color: #000080;font-style:italic;">-- printf(1,"%d %s\n",{n,mmnn(n)}) // Generate b-file for A131382 (1..1000)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000080;font-style:italic;">--printf(1,"%d %s\n",{1e3,mmnn(1e3)}) -- 0.6s
--printf(1,"%d %s\n",{1e4,mmnn(1e4)}) -- 1min 8s
--printf(1,"%d %s\n",{2e4,mmnn(2e4)}) -- crashes on 32 bit, 6 minutes and 18s on 64 bit
--printf(1,"%d %s\n",{1e6,mmnn(1e6)}) -- not a chance!</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{out}}
Coincidentally taking exactly as long to get to 1000 as the above took to get to 369, as above with slightly different line breaks, plus
<pre>
<snip>
995: 2010040201005025125628140703517587939698492462311557788944723618090452261306532663316582914572864321608040201
996: 1907630522088353413654618473895481927710843373493975903614457831325301204819277108433734939759036144578313253
997: 1003009027081243731193580742226579739217652958876629889669007021063189568706118355065195586760279839518555667
998: 2004008016032064128256513026052104208416833667234468937875751503006012024048096192384769539078156312625250501
999: 1001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001
1000: 1999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
"2 minutes and 29s"
</pre>
 
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
{{Trans|ALGOL 68|but finds the multiples of 1..39, as the 8080 PL/M compiler supports (unsigned) 8 and 16 bit numbers. The minimum multiple of 40 whose digit sum is 40 is larger than 65535.}}
<syntaxhighlight lang="plm">
100H: /* FIND THE SMALLEST M WHERE M*N = DIGIT SUM OF N, N IN 1 .. 70 */
 
/* CP/M BDOS SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* TASK */
 
DECLARE TRUE LITERALLY '0FFH', FALSE LITERALLY '0';
DIGIT$SUM: PROCEDURE( N )ADDRESS; /* RETURNS THE DIGIT SUM OF N */
DECLARE N ADDRESS;
IF N < 10 THEN RETURN N;
ELSE DO;
DECLARE ( RESULT, V ) ADDRESS;
RESULT = N MOD 10;
V = N / 10;
DO WHILE V > 0;
RESULT = RESULT + ( V MOD 10 );
V = V / 10;
END;
RETURN RESULT;
END;
END DIGIT$SUM ;
 
/* SHOW THE MINIMUM MULTIPLE OF N WHERE THE DIGIT SUM OF THE MULTIPLE IS N */
DECLARE ( M, N ) ADDRESS;
DECLARE FOUND$MULTIPLE BYTE;
DO N = 1 TO 39;
FOUND$MULTIPLE = FALSE;
M = 0;
DO WHILE NOT FOUND$MULTIPLE;
M = M + 1;
IF DIGIT$SUM( M * N ) = N THEN DO;
FOUND$MULTIPLE = TRUE;
CALL PR$CHAR( ' ' );
IF M < 10000 THEN DO;
CALL PR$CHAR( ' ' );
IF M < 1000 THEN DO;
CALL PR$CHAR( ' ' );
IF M < 100 THEN DO;
CALL PR$CHAR( ' ' );
IF M < 10 THEN CALL PR$CHAR( ' ' );
END;
END;
END;
CALL PR$NUMBER( M );
IF N MOD 8 = 0 THEN CALL PR$NL;
END;
END;
END;
 
EOF
</syntaxhighlight>
{{out}}
<pre>
1 1 1 1 1 1 1 1
1 19 19 4 19 19 13 28
28 11 46 199 19 109 73 37
199 73 37 271 172 1333 289 559
1303 847 1657 833 1027 1576 1282
</pre>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">main:-
between(1, 40, N),
min_mult_dsum(N, M),
Line 1,569 ⟶ 2,216:
divmod(N, 10, M, Digit),
S2 is S1 + Digit,
digit_sum(M, Sum, S2).</langsyntaxhighlight>
 
{{out}}
Line 1,580 ⟶ 2,227:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">'''A131382'''
 
from itertools import count, islice
Line 1,670 ⟶ 2,317:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> 1 1 1 1 1 1 1 1 1 19
Line 1,679 ⟶ 2,326:
=={{header|Raku}}==
 
<syntaxhighlight lang="raku" perl6line>sub min-mult-dsum ($n) { (1..∞).first: (* × $n).comb.sum == $n }
 
say .fmt("%2d: ") ~ .&min-mult-dsum for flat 1..40, 41..70;</langsyntaxhighlight>
{{out}}
<pre> 1: 1
Line 1,753 ⟶ 2,400:
69: 1157971
70: 12842857</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Table MinMult 1 70 10 10>;
};
 
MinMult {
s.N = <MinMult s.N 1>;
s.N s.M, <DigSum <* s.M s.N>>: s.N = s.M;
s.N s.M = <MinMult s.N <+ s.M 1>>;
};
 
DigSum {
0 = 0;
s.N, <Symb s.N>: s.D e.R = <+ <Numb s.D> <DigSum <Numb e.R>>>;
};
 
Cell {
s.Size e.X, <Lenw e.X>: s.Cur e.Y,
<Compare s.Cur s.Size>: '-' = <Cell s.Size ' 'e.X>;
s.Size e.X = e.X;
};
 
Table {
s.F s.N s.Max s.Width s.CW =
<Table s.F s.N s.Max s.Width s.CW s.Width ()>;
s.F s.N s.Max s.Width s.CW 0 (e.Line) =
<Prout e.Line>
<Table s.F s.N s.Max s.Width s.CW s.Width ()>;
s.F s.N s.Max s.Width s.CW s.Col (e.Line), <Compare s.N s.Max>: '+' =
<Prout e.Line>;
s.F s.N s.Max s.Width s.CW s.Col (e.Line) =
<Table s.F <+ s.N 1> s.Max s.Width s.CW <- s.Col 1>
(e.Line <Cell s.CW <Symb <Mu s.F s.N>>>)>;
};</syntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
 
=={{header|RPL}}==
≪ 0 SWAP '''WHILE''' DUP '''REPEAT'''
10 MOD LAST / FLOOR SWAP ROT + SWAP
'''END''' DROP
≫ ‘'''∑DIG'''’ STO
≪ 0 '''DO''' 1 + DUP2 * '''UNTIL ∑DIG''' 3 PICK == '''END''' SWAP DROP
≫ ‘'''A131382'''’ STO
 
≪ { } 1 40 '''FOR''' j j '''A131382''' + '''NEXT''' ≫ EVAL
{{out}}
<pre>
1: { 1 1 1 1 1 1 1 1 1 19 19 4 19 19 13 28 28 11 46 199 19 109 73 37 199 73 37 271 172 1333 289 559 1303 847 1657 833 1027 1576 1282 17497 }
</pre>
Runs in 98 minutes on a HP-28S.
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">a131382 = (0..).lazy.map{|n| (1..).detect{|m|(n*m).digits.sum == n} }
a131382.take(70).each_slice(10){|slice| puts "%8d"*slice.size % slice }</syntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 1
19 19 4 19 19 13 28 28 11 46
199 19 109 73 37 199 73 37 271 172
1333 289 559 1303 847 1657 833 1027 1576 1282
17497 4339 2119 2323 10909 11111 12826 14617 14581 16102
199999 17449 38269 56413 37037 1108909 142498 103507 154981 150661
1333333 163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program minimum_multiple_of_m_where_digit_sum_equals_m;
loop for n in [1..70] do
putchar(lpad(str minmult n, 9));
if n mod 10=0 then print; end if;
end loop;
 
op minmult(m);
n := 1;
(while digsum(n*m) /= m) n +:= 1; end;
return n;
end op;
 
op digsum(n);
return +/[[n mod 10, n div:=10](1) : until n=0];
end op;
end program;</syntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var e = Enumerator({|f|
for n in (1..Inf) {
 
var k = 0
while (k.sumdigits != n) {
k += n
}
 
f(k/n)
}
})
 
var N = 60
var A = []
 
e.each {|v|
A << v
say A.splice.map { '%7s' % _ }.join(' ') if (A.len == 10)
break if (--N <= 0)
}</syntaxhighlight>
{{out}}
<pre>
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
</pre>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
func digitSum(_ num: Int) -> Int {
Line 1,774 ⟶ 2,550:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,791 ⟶ 2,567:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
Line 1,801 ⟶ 2,577:
res.add(m)
}
for (chunk in Lst.chunks(res, 10)) Fmt.printtprint("$,10d", chunkres, 10)</langsyntaxhighlight>
 
{{out}}
Line 1,815 ⟶ 2,591:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func SumDigits(N); \Return sum of digits in N
int N, S;
[S:= 0;
Line 1,834 ⟶ 2,610:
N:= N+1;
until C >= 40+30;
]</langsyntaxhighlight>
 
{{out}}
2,094

edits