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

Content added Content deleted
(Added Go)
m (syntax highlighting fixup automation)
Line 23: Line 23:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find the smallest m where mn = digit sum of n, n in 1 .. 70 #
<syntaxhighlight 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 #
# returns the digit sum of n, n must be >= 0 #
OP DIGITSUM = ( INT n )INT:
OP DIGITSUM = ( INT n )INT:
Line 47: Line 47:
OD
OD
OD
OD
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 62: Line 62:
=={{header|APL}}==
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|Dyalog APL}}
<lang APL>{n←⍵ ⋄ (+∘1)⍣{n=+/10⊥⍣¯1⊢⍺×n}⊢0 } ¨ 7 10⍴⍳70</lang>
<syntaxhighlight lang="apl">{n←⍵ ⋄ (+∘1)⍣{n=+/10⊥⍣¯1⊢⍺×n}⊢0 } ¨ 7 10⍴⍳70</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
<pre> 1 1 1 1 1 1 1 1 1 19
Line 72: Line 72:
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</pre>
=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MINIMUM_MULTIPLE_OF_M_WHERE_DIGITAL_SUM_EQUALS_M.AWK
# syntax: GAWK -f MINIMUM_MULTIPLE_OF_M_WHERE_DIGITAL_SUM_EQUALS_M.AWK
BEGIN {
BEGIN {
Line 95: Line 95:
return(s)
return(s)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 110: Line 110:
=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|BASIC256}}===
==={{header|BASIC256}}===
<lang BASIC256>c = 0
<syntaxhighlight lang="basic256">c = 0
n = 1
n = 1
while c < 70
while c < 70
Line 129: Line 129:
n += 1
n += 1
end while
end while
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 137: Line 137:
==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===
{{trans|Phix}}
{{trans|Phix}}
<lang freebasic>#define floor(x) ((x*2.0-0.5) Shr 1)
<syntaxhighlight lang="freebasic">#define floor(x) ((x*2.0-0.5) Shr 1)


Dim As Integer c = 0, n = 1
Dim As Integer c = 0, n = 1
Line 157: Line 157:
Loop
Loop
Sleep
Sleep
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
<pre> 1 1 1 1 1 1 1 1 1 19
Line 168: Line 168:


==={{header|Yabasic}}===
==={{header|Yabasic}}===
<lang yabasic>c = 0
<syntaxhighlight lang="yabasic">c = 0
n = 1
n = 1
while c < 70
while c < 70
Line 187: Line 187:
n = n + 1
n = n + 1
wend
wend
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 194: Line 194:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


unsigned digit_sum(unsigned n) {
unsigned digit_sum(unsigned n) {
Line 216: Line 216:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
<pre> 1 1 1 1 1 1 1 1 1 19
Line 227: Line 227:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iomanip>
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
#include <iostream>


Line 246: Line 246:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 260: Line 260:


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>digit_sum = proc (n: int) returns (int)
<syntaxhighlight lang="clu">digit_sum = proc (n: int) returns (int)
sum: int := 0
sum: int := 0
while n > 0 do
while n > 0 do
Line 291: Line 291:
if n // 10 = 0 then stream$putl(po, "") end
if n // 10 = 0 then stream$putl(po, "") end
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 1 1 1 1 1 1 1 1 19
<pre> 1 1 1 1 1 1 1 1 1 19
Line 302: Line 302:


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. A131382.
PROGRAM-ID. A131382.
Line 343: Line 343:
ADD-DIGIT.
ADD-DIGIT.
ADD DIGITS(D) TO DIGITSUM.</lang>
ADD DIGITS(D) TO DIGITSUM.</syntaxhighlight>
{{out}}
{{out}}
<pre style='height:50ex;'>A( 1) = 1
<pre style='height:50ex;'>A( 1) = 1
Line 387: Line 387:


=={{header|Cowgol}}==
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


sub digit_sum(n: uint32): (sum: uint8) is
sub digit_sum(n: uint32): (sum: uint8) is
Line 411: Line 411:
end if;
end if;
n := n + 1;
n := n + 1;
end loop;</lang>
end loop;</syntaxhighlight>
{{out}}
{{out}}
<pre>1 1 1 1 1 1 1 1 1 19
<pre>1 1 1 1 1 1 1 1 1 19
Line 422: Line 422:


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>/* this is very slow even in emulation - if you're going to try it
<syntaxhighlight 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;
* on a real 8-bit micro I'd recommend setting this back to 40;
* it does, however, eventually get there */
* it does, however, eventually get there */
Line 455: Line 455:
if (n & 7) = 0 then writeln() fi
if (n & 7) = 0 then writeln() fi
od
od
corp</lang>
corp</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 1 1 1 1 1 1 1
<pre> 1 1 1 1 1 1 1 1
Line 468: Line 468:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Minimum multiple of m where digital sum equals m. Nigel Galloway: January 31st., 2022
// 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
let SoD n=let rec SoD n=function 0L->int n |g->SoD(n+g%10L)(g/10L) in SoD 0L n
Line 477: Line 477:
fN ((((pown 10L (g/9))-1L)+int64(g%9)*(pown 10L (g/9)))/int64 g)
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 "")
Seq.initInfinite((+)1>>A131382)|>Seq.take 70|>Seq.chunkBySize 10|>Seq.iter(fun n->n|>Seq.iter(printf "%13d "); printfn "")
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 489: Line 489:
</pre>
</pre>
=={{header|FOCAL}}==
=={{header|FOCAL}}==
<lang focal>01.10 F N=1,40;D 2
<syntaxhighlight lang="focal">01.10 F N=1,40;D 2
01.20 Q
01.20 Q


Line 503: Line 503:
03.30 S S=S+(D-E*10)
03.30 S S=S+(D-E*10)
03.40 S D=E
03.40 S D=E
03.50 I (-D)3.2</lang>
03.50 I (-D)3.2</syntaxhighlight>
{{out}}
{{out}}
<pre style='height:50ex;'>N= 1 M= 1
<pre style='height:50ex;'>N= 1 M= 1
Line 549: Line 549:
=={{header|Forth}}==
=={{header|Forth}}==
{{works with|Gforth}}
{{works with|Gforth}}
<lang forth>: digit-sum ( u -- u )
<syntaxhighlight lang="forth">: digit-sum ( u -- u )
dup 10 < if exit then
dup 10 < if exit then
10 /mod recurse + ;
10 /mod recurse + ;
Line 563: Line 563:


70 main
70 main
bye</lang>
bye</syntaxhighlight>


{{out}}
{{out}}
Line 578: Line 578:
=={{header|Go}}==
=={{header|Go}}==
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
<lang Go>package main
<syntaxhighlight lang="go">package main


import "rcu"
import "rcu"
Line 592: Line 592:
}
}
rcu.PrintTable(res, 7, 10, true)
rcu.PrintTable(res, 7, 10, true)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 609: Line 609:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.Bifunctor (first)
<syntaxhighlight lang="haskell">import Data.Bifunctor (first)
import Data.List (elemIndex, intercalate, transpose)
import Data.List (elemIndex, intercalate, transpose)
import Data.List.Split (chunksOf)
import Data.List.Split (chunksOf)
Line 640: Line 640:
let ws = maximum . fmap length <$> transpose rows
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</lang>
in unlines $ intercalate gap . zipWith pw ws <$> rows</syntaxhighlight>
{{Out}}
{{Out}}
<pre> 1 1 1 1 1 1 1 1 1 19
<pre> 1 1 1 1 1 1 1 1 1 19
Line 651: Line 651:
Implementation:
Implementation:


<syntaxhighlight lang="j">
<lang J>
findfirst=: {{
findfirst=: {{
($:@((+1+i.@+:)@#)@[`(+&{. I.)@.(1 e. ]) u) ,1
($:@((+1+i.@+:)@#)@[`(+&{. I.)@.(1 e. ]) u) ,1
Line 658: Line 658:
A131382=: {{y&{{x = sumdigits x*y}} findfirst}}"0
A131382=: {{y&{{x = sumdigits x*y}} findfirst}}"0


sumdigits=: +/@|:@(10&#.inv)</lang>
sumdigits=: +/@|:@(10&#.inv)</syntaxhighlight>


Task example:
Task example:
<lang J> A131382 1+i.4 10
<syntaxhighlight lang="j"> A131382 1+i.4 10
1 1 1 1 1 1 1 1 1 19
1 1 1 1 1 1 1 1 1 19
19 4 19 19 13 28 28 11 46 199
19 4 19 19 13 28 28 11 46 199
19 109 73 37 199 73 37 271 172 1333
19 109 73 37 199 73 37 271 172 1333
289 559 1303 847 1657 833 1027 1576 1282 17497</lang>
289 559 1303 847 1657 833 1027 1576 1282 17497</syntaxhighlight>


Stretch example:
Stretch example:
<lang J> A131382 41+i.3 10
<syntaxhighlight lang="j"> A131382 41+i.3 10
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
4339 2119 2323 10909 11111 12826 14617 14581 16102 199999
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
17449 38269 56413 37037 1108909 142498 103507 154981 150661 1333333
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</lang>
163918 322579 315873 937342 1076923 1030303 880597 1469116 1157971 12842857</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>minproddigsum(n) = findfirst(i -> sum(digits(n * i)) == n, 1:typemax(Int32))
<syntaxhighlight lang="julia">minproddigsum(n) = findfirst(i -> sum(digits(n * i)) == n, 1:typemax(Int32))


for j in 1:70
for j in 1:70
print(lpad(minproddigsum(j), 10), j % 7 == 0 ? "\n" : "")
print(lpad(minproddigsum(j), 10), j % 7 == 0 ? "\n" : "")
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
1 1 1 1 1 1 1
1 1 1 1 1 1 1
Line 694: Line 694:


=={{header|MAD}}==
=={{header|MAD}}==
<lang MAD> NORMAL MODE IS INTEGER
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
VECTOR VALUES FMT = $2HA(,I2,4H) = ,I8*$
VECTOR VALUES FMT = $2HA(,I2,4H) = ,I8*$
Line 711: Line 711:
TRANSFER TO DIGIT
TRANSFER TO DIGIT
END OF FUNCTION
END OF FUNCTION
END OF PROGRAM</lang>
END OF PROGRAM</syntaxhighlight>
{{out}}
{{out}}
<pre style='height:50ex;'>A( 1) = 1
<pre style='height:50ex;'>A( 1) = 1
Line 789: Line 789:
Constructing minimal start number with sum of digits = m -> k+9+9+9+9+9+9 <BR>
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.
Break up in parts of 4 digits.Could be more optimized.
<lang pascal>program m_by_n_sumofdgts_m;
<syntaxhighlight lang="pascal">program m_by_n_sumofdgts_m;
//Like https://oeis.org/A131382/b131382.txt
//Like https://oeis.org/A131382/b131382.txt
{$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$ENDIF}
{$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$ENDIF}
Line 1,014: Line 1,014:
writeln('Total runtime ',GetTickCount64-T0,' ms');
writeln('Total runtime ',GetTickCount64-T0,' ms');
{$IFDEF WINDOWS} readln{$ENDIF}
{$IFDEF WINDOWS} readln{$ENDIF}
end.</lang>
end.</syntaxhighlight>
{{out|@TIO.RUN}}
{{out|@TIO.RUN}}
<pre>
<pre>
Line 1,083: Line 1,083:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl


use strict; # https://rosettacode.org/wiki/Minimum_multiple_of_m_where_digital_sum_equals_m
use strict; # https://rosettacode.org/wiki/Minimum_multiple_of_m_where_digital_sum_equals_m
Line 1,095: Line 1,095:
$m;
$m;
} 1 .. 70;
} 1 .. 70;
print "@answers\n\n" =~ s/.{65}\K /\n/gr;</lang>
print "@answers\n\n" =~ s/.{65}\K /\n/gr;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,108: Line 1,108:
=={{header|Phix}}==
=={{header|Phix}}==
{{trans|XPL0}}
{{trans|XPL0}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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>
<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,126: Line 1,126:
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,141: Line 1,141:
{{libheader|Phix/online}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/mmnn.htm here].
You can run this online [http://phix.x10.mx/p2js/mmnn.htm here].
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\mmnn.exw</span>
<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>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 1,497: Line 1,497:
<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: #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>
<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>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,577: Line 1,577:
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>
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.
Translation of the C++ code on [[oeis:A002998|A002998]] but with the additional final divide for [[oeis:A131382|A131382]] and significantly clearer imnsho.
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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;">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>
Line 1,638: Line 1,638:
<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: #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>
<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>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{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
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
Line 1,654: Line 1,654:
=={{header|Prolog}}==
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{works with|SWI Prolog}}
<lang prolog>main:-
<syntaxhighlight lang="prolog">main:-
between(1, 40, N),
between(1, 40, N),
min_mult_dsum(N, M),
min_mult_dsum(N, M),
Line 1,683: Line 1,683:
divmod(N, 10, M, Digit),
divmod(N, 10, M, Digit),
S2 is S1 + Digit,
S2 is S1 + Digit,
digit_sum(M, Sum, S2).</lang>
digit_sum(M, Sum, S2).</syntaxhighlight>


{{out}}
{{out}}
Line 1,694: Line 1,694:


=={{header|Python}}==
=={{header|Python}}==
<lang python>'''A131382'''
<syntaxhighlight lang="python">'''A131382'''


from itertools import count, islice
from itertools import count, islice
Line 1,784: Line 1,784:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre> 1 1 1 1 1 1 1 1 1 19
<pre> 1 1 1 1 1 1 1 1 1 19
Line 1,793: Line 1,793:
=={{header|Raku}}==
=={{header|Raku}}==


<lang perl6>sub min-mult-dsum ($n) { (1..∞).first: (* × $n).comb.sum == $n }
<syntaxhighlight lang="raku" line>sub min-mult-dsum ($n) { (1..∞).first: (* × $n).comb.sum == $n }


say .fmt("%2d: ") ~ .&min-mult-dsum for flat 1..40, 41..70;</lang>
say .fmt("%2d: ") ~ .&min-mult-dsum for flat 1..40, 41..70;</syntaxhighlight>
{{out}}
{{out}}
<pre> 1: 1
<pre> 1: 1
Line 1,869: Line 1,869:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var e = Enumerator({|f|
<syntaxhighlight lang="ruby">var e = Enumerator({|f|
for n in (1..Inf) {
for n in (1..Inf) {


Line 1,888: Line 1,888:
say A.splice.map { '%7s' % _ }.join(' ') if (A.len == 10)
say A.splice.map { '%7s' % _ }.join(' ') if (A.len == 10)
break if (--N <= 0)
break if (--N <= 0)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,900: Line 1,900:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


func digitSum(_ num: Int) -> Int {
func digitSum(_ num: Int) -> Int {
Line 1,919: Line 1,919:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,936: Line 1,936:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "./math" for Int
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./seq" for Lst
import "./seq" for Lst
import "./fmt" for Fmt
import "./fmt" for Fmt
Line 1,946: Line 1,946:
res.add(m)
res.add(m)
}
}
for (chunk in Lst.chunks(res, 10)) Fmt.print("$,10d", chunk)</lang>
for (chunk in Lst.chunks(res, 10)) Fmt.print("$,10d", chunk)</syntaxhighlight>


{{out}}
{{out}}
Line 1,960: Line 1,960:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>func SumDigits(N); \Return sum of digits in N
<syntaxhighlight lang="xpl0">func SumDigits(N); \Return sum of digits in N
int N, S;
int N, S;
[S:= 0;
[S:= 0;
Line 1,979: Line 1,979:
N:= N+1;
N:= N+1;
until C >= 40+30;
until C >= 40+30;
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}