Wasteful, equidigital and frugal numbers: Difference between revisions
Wasteful, equidigital and frugal numbers (view source)
Revision as of 20:30, 28 August 2022
, 1 year agosyntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 50:
<br><br>
=={{header|F_Sharp|F#}}==
<
// 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>
{{out}}
<pre>
Line 68:
=={{header|J}}==
Brute force implementation:<
D=: [ +/@:I __ -.&1@,@q: ]
typ=: ~:&1@] * *@(I-D)"0 NB. _1: wasteful, 0: equidigital, 1: frugal</
Task examples (base 10):<
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</
Task examples (base 11):<
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</
=={{header|Julia}}==
<
"""
Line 160:
end
end
</syntaxhighlight>
Output is the same as Wren example.
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
FactorIntegerDigits[n_] := Module[{},
fi = FactorInteger[n];
Line 188:
Print["Frugal"]
Stats[frugal]</
{{out}}
<pre>Wasteful
Line 207:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use experimental 'for_list';
use ntheory <factor todigitstring>;
Line 235:
}
say "\nOf the positive integers up to one million:\n$totals";
}</
{{out}}
<pre style="height:110ex">In base 10:
Line 307:
=={{header|Phix}}==
{{trans|Wren}}
<!--<
<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>
<!--</
Output identical to Wren
=={{header|Raku}}==
<syntaxhighlight lang="raku"
use Lingua::EN::Numbers;
Line 395:
say " Extravagant: {comma $extravagant}\n Equidigital: {comma $equidigital}\n Economical: {comma $economical}";
%cache{$base} = Empty;
}</
{{out}}
<pre>In Base 10:
Line 463:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<
import "./seq" for Lst
import "./fmt" for Fmt
Line 525:
Fmt.print(" Frugal numbers : $6d", fc2)
System.print()
}</
{{out}}
|