Wasteful, equidigital and frugal numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 50: | Line 50: | ||
<br><br> |
<br><br> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Frugal, equidigital, and wasteful numbers. Nigel Galloway: July 26th., 2022 |
// Frugal, equidigital, and wasteful numbers. Nigel Galloway: July 26th., 2022 |
||
let rec fG n g=match g/10L with 0L->n+1 |g->fG(n+1) g |
let rec fG n g=match g/10L with 0L->n+1 |g->fG(n+1) g |
||
Line 56: | Line 56: | ||
let Frugal,Equidigital,Wasteful=let FEW n=Seq.initInfinite((+)2)|>Seq.filter(fun g->n(fG 0 g)(fN g)) in (("Frugal",FEW(>)),("Equidigital",seq{yield 1; yield! FEW(=)}),("Wasteful",FEW(<))) |
let Frugal,Equidigital,Wasteful=let FEW n=Seq.initInfinite((+)2)|>Seq.filter(fun g->n(fG 0 g)(fN g)) in (("Frugal",FEW(>)),("Equidigital",seq{yield 1; yield! FEW(=)}),("Wasteful",FEW(<))) |
||
[Frugal;Equidigital;Wasteful]|>List.iter(fun(n,g)->printf $"%s{n}: 10 thousandth is %d{Seq.item 9999 g}; There are %d{Seq.length (g|>Seq.takeWhile((>)1000000))} < 1 million\n First 50: "; g|>Seq.take 50|>Seq.iter(printf "%d "); printfn "") |
[Frugal;Equidigital;Wasteful]|>List.iter(fun(n,g)->printf $"%s{n}: 10 thousandth is %d{Seq.item 9999 g}; There are %d{Seq.length (g|>Seq.takeWhile((>)1000000))} < 1 million\n First 50: "; g|>Seq.take 50|>Seq.iter(printf "%d "); printfn "") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 68: | Line 68: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Brute force implementation:< |
Brute force implementation:<syntaxhighlight lang="j">I=: #@(#.inv)"0 |
||
D=: [ +/@:I __ -.&1@,@q: ] |
D=: [ +/@:I __ -.&1@,@q: ] |
||
typ=: ~:&1@] * *@(I-D)"0 NB. _1: wasteful, 0: equidigital, 1: frugal</ |
typ=: ~:&1@] * *@(I-D)"0 NB. _1: wasteful, 0: equidigital, 1: frugal</syntaxhighlight> |
||
Task examples (base 10):< |
Task examples (base 10):<syntaxhighlight lang="j"> (9999&{, 50&{.)1+I._1=b10 NB. wasteful |
||
14346 4 6 8 9 12 18 20 22 24 26 28 30 33 34 36 38 39 40 42 44 45 46 48 50 51 52 54 55 56 57 58 60 62 63 65 66 68 69 70 72 74 75 76 77 78 80 82 84 85 86 |
14346 4 6 8 9 12 18 20 22 24 26 28 30 33 34 36 38 39 40 42 44 45 46 48 50 51 52 54 55 56 57 58 60 62 63 65 66 68 69 70 72 74 75 76 77 78 80 82 84 85 86 |
||
(9999&{, 50&{.)1+I. 0=b10 NB. equidigital |
(9999&{, 50&{.)1+I. 0=b10 NB. equidigital |
||
Line 83: | Line 83: | ||
165645 |
165645 |
||
+/1e6>1+I. 1=b10 NB. frugal |
+/1e6>1+I. 1=b10 NB. frugal |
||
3123</ |
3123</syntaxhighlight> |
||
Task examples (base 11):< |
Task examples (base 11):<syntaxhighlight lang="j"> (9999&{, 50&{.)1+I._1=b11 NB. wasteful |
||
12890 4 6 8 9 10 12 18 20 22 24 26 28 30 33 34 36 38 39 40 42 44 45 46 48 50 51 52 54 55 56 57 58 60 62 63 65 66 68 69 70 72 74 75 76 77 78 80 82 84 85 |
12890 4 6 8 9 10 12 18 20 22 24 26 28 30 33 34 36 38 39 40 42 44 45 46 48 50 51 52 54 55 56 57 58 60 62 63 65 66 68 69 70 72 74 75 76 77 78 80 82 84 85 |
||
(9999&{, 50&{.)1+I. 0=b11 NB. equidigital |
(9999&{, 50&{.)1+I. 0=b11 NB. equidigital |
||
Line 96: | Line 96: | ||
200710 |
200710 |
||
+/1e6>1+I. 1=b11 NB. frugal |
+/1e6>1+I. 1=b11 NB. frugal |
||
3428</ |
3428</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="ruby">using Primes |
||
""" |
""" |
||
Line 160: | Line 160: | ||
end |
end |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output is the same as Wren example. |
Output is the same as Wren example. |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[FactorIntegerDigits, ID, Stats] |
||
FactorIntegerDigits[n_] := Module[{}, |
FactorIntegerDigits[n_] := Module[{}, |
||
fi = FactorInteger[n]; |
fi = FactorInteger[n]; |
||
Line 188: | Line 188: | ||
Print["Frugal"] |
Print["Frugal"] |
||
Stats[frugal]</ |
Stats[frugal]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wasteful |
<pre>Wasteful |
||
Line 207: | Line 207: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use v5.36; |
||
use experimental 'for_list'; |
use experimental 'for_list'; |
||
use ntheory <factor todigitstring>; |
use ntheory <factor todigitstring>; |
||
Line 235: | Line 235: | ||
} |
} |
||
say "\nOf the positive integers up to one million:\n$totals"; |
say "\nOf the positive integers up to one million:\n$totals"; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:110ex">In base 10: |
<pre style="height:110ex">In base 10: |
||
Line 307: | Line 307: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
<!--< |
<!--<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;">function</span> <span style="color: #000000;">analyze</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: #000000;">b</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">analyze</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: #000000;">b</span><span style="color: #0000FF;">)</span> |
||
Line 364: | Line 364: | ||
<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: #000000;">fmt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">&</span><span style="color: #000000;">w3</span><span style="color: #0000FF;">&</span><span style="color: #000000;">w10k</span><span style="color: #0000FF;">&</span><span style="color: #000000;">c2</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: #000000;">fmt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">&</span><span style="color: #000000;">w3</span><span style="color: #0000FF;">&</span><span style="color: #000000;">w10k</span><span style="color: #0000FF;">&</span><span style="color: #000000;">c2</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
Output identical to Wren |
Output identical to Wren |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>use Prime::Factor; |
||
use Lingua::EN::Numbers; |
use Lingua::EN::Numbers; |
||
Line 395: | Line 395: | ||
say " Extravagant: {comma $extravagant}\n Equidigital: {comma $equidigital}\n Economical: {comma $economical}"; |
say " Extravagant: {comma $extravagant}\n Equidigital: {comma $equidigital}\n Economical: {comma $economical}"; |
||
%cache{$base} = Empty; |
%cache{$base} = Empty; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>In Base 10: |
<pre>In Base 10: |
||
Line 463: | Line 463: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "./math" for Int |
||
import "./seq" for Lst |
import "./seq" for Lst |
||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
Line 525: | Line 525: | ||
Fmt.print(" Frugal numbers : $6d", fc2) |
Fmt.print(" Frugal numbers : $6d", fc2) |
||
System.print() |
System.print() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |