Wasteful, equidigital and frugal numbers: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 50:
<br><br>
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// 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
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(<)))
[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}}
<pre>
Line 68:
=={{header|J}}==
 
Brute force implementation:<langsyntaxhighlight Jlang="j">I=: #@(#.inv)"0
D=: [ +/@:I __ -.&1@,@q: ]
typ=: ~:&1@] * *@(I-D)"0 NB. _1: wasteful, 0: equidigital, 1: frugal</langsyntaxhighlight>
 
Task examples (base 10):<langsyntaxhighlight Jlang="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
(9999&{, 50&{.)1+I. 0=b10 NB. equidigital
Line 83:
165645
+/1e6>1+I. 1=b10 NB. frugal
3123</langsyntaxhighlight>
 
Task examples (base 11):<langsyntaxhighlight Jlang="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
(9999&{, 50&{.)1+I. 0=b11 NB. equidigital
Line 96:
200710
+/1e6>1+I. 1=b11 NB. frugal
3428</langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="ruby">using Primes
 
"""
Line 160:
end
end
</syntaxhighlight>
</lang>
Output is the same as Wren example.
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[FactorIntegerDigits, ID, Stats]
FactorIntegerDigits[n_] := Module[{},
fi = FactorInteger[n];
Line 188:
 
Print["Frugal"]
Stats[frugal]</langsyntaxhighlight>
{{out}}
<pre>Wasteful
Line 207:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use v5.36;
use experimental 'for_list';
use ntheory <factor todigitstring>;
Line 235:
}
say "\nOf the positive integers up to one million:\n$totals";
}</langsyntaxhighlight>
{{out}}
<pre style="height:110ex">In base 10:
Line 307:
=={{header|Phix}}==
{{trans|Wren}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
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: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
Output identical to Wren
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>use Prime::Factor;
use Lingua::EN::Numbers;
 
Line 395:
say " Extravagant: {comma $extravagant}\n Equidigital: {comma $equidigital}\n Economical: {comma $economical}";
%cache{$base} = Empty;
}</langsyntaxhighlight>
{{out}}
<pre>In Base 10:
Line 463:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
Line 525:
Fmt.print(" Frugal numbers : $6d", fc2)
System.print()
}</langsyntaxhighlight>
 
{{out}}
10,327

edits