Wasteful, equidigital and frugal numbers: Difference between revisions

Content added Content deleted
m (Typo)
(J draft)
Line 47: Line 47:
* [[oeis: A046759|OEIS: A046759 - Economical numbers]]
* [[oeis: A046759|OEIS: A046759 - Economical numbers]]
<br><br>
<br><br>
=={{header}J}}==

Brute force implementation:<lang J>I=: #@(#.inv)"0
D=: [ +/@:I __ (#~1<])@,@q: ]
typ=: *@(I-D)"0 NB. _1: wasteful, 0: equidigital, 1: frugal</lang>

Task examples (base 10):<lang J> b10=: 10 typ 1+i.3e6
(9999 1e4&{, 50&{.)1+I._1=b10 NB. wasteful
14346 14348 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 1e4&{, 50&{.)1+I. 0=b10 NB. equidigital
33773 33777 2 3 5 7 10 11 13 14 15 16 17 19 21 23 25 27 29 31 32 35 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97 101 103 105 106 107 109 111 112 113 115 118 119 121
(9999 1e4&{, 50&{.)1+I. 1=b10 NB. frugal
1953031 1953125 1 125 128 243 256 343 512 625 729 1024 1029 1215 1250 1280 1331 1369 1458 1536 1681 1701 1715 1792 1849 1875 2048 2187 2197 2209 2401 2560 2809 3125 3481 3584 3645 3721 4096 4374 4375 4489 4802 4913 5041 5103 5329 6241 6250 6561 6859 6889
+/1e6>1+I._1=b10 NB. wasteful
831231
+/1e6>1+I. 0=b10 NB. equidigital
165644
+/1e6>1+I. 1=b10 NB. frugal
3124</lang>

It was not clear to me whether the 10000th was supposed to be the real 10000th (index 9999 in J) or the number after that. So.. here I show both.


=={{header|Phix}}==
=={{header|Phix}}==
{{trans|Wren}}
{{trans|Wren}}