Eban numbers: Difference between revisions
m →{{header|REXX}}: added wording in the REXX section header. |
Thundergnat (talk | contribs) →{{header|Perl 6}}: Add a Perl 6 example |
||
Line 33: | Line 33: | ||
:* The OEIS entry: [[http://oeis.org/A006933 A6933, eban numbers]]. |
:* The OEIS entry: [[http://oeis.org/A006933 A6933, eban numbers]]. |
||
<br><br> |
<br><br> |
||
=={{header|Perl 6}}== |
|||
{{works with|Rakudo|2018.12}} |
|||
<lang perl6>use Lingua::EN::Numbers::Cardinal; |
|||
sub eban (@seq) { (@seq».Int).map: { next if .&cardinal.contains('e'); $_ } } |
|||
sub comma { $^i.flip.comb(3).join(',').flip } |
|||
my @eban = flat ((1 .. 100),).map: *.&eban; |
|||
my @orders = ( ( 1e3, 2e3 ... 9e3 ), |
|||
( 1e4, 2e4 ... 9e4 ), |
|||
( 1e6, 2e6 ... 9e6 ), |
|||
( 1e7, 2e7 ... 9e7 ), |
|||
( 1e9, 2e9 ... 9e9 ), |
|||
).map: *.&eban; |
|||
for @orders -> @order { |
|||
my @these; |
|||
for @order { |
|||
my @extend = flat $_, flat @eban X+ $_; |
|||
@these.append: @extend; |
|||
} |
|||
@eban.append: @these |
|||
} |
|||
my $k = @eban.first( * > 100, :k ); |
|||
put @eban[^$k]; |
|||
say "Up to 100: ", +@eban[^$k]; |
|||
say '=' x 40; |
|||
my $b = @eban.first( * >= 1000, :k ); |
|||
my $f = @eban.first( * >= 4000, :k ); |
|||
put @eban[$b .. $f]; |
|||
say "From 1,000 to 4,000: ", +@eban[$b .. $f]; |
|||
say '=' x 40; |
|||
for (1e4, 1e5, 1e6, 1e7, 1e9)».Int |
|||
-> $e { |
|||
my $f = @eban.first( * >= $e, :k ); |
|||
say "Up to {comma $e}: ", +@eban[^$f]; |
|||
say '=' x 40; |
|||
}</lang> |
|||
{{out}} |
|||
<pre>2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 |
|||
Up to 100: 19 |
|||
======================================== |
|||
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 |
|||
From 1,000 to 4,000: 21 |
|||
======================================== |
|||
Up to 10,000: 79 |
|||
======================================== |
|||
Up to 100,000: 399 |
|||
======================================== |
|||
Up to 1,000,000: 399 |
|||
======================================== |
|||
Up to 10,000,000: 1599 |
|||
======================================== |
|||
Up to 1,000,000,000: 7999 |
|||
========================================</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
Revision as of 01:15, 18 February 2019
{draft task}
- Definition
An eban number is a number that has no letter e in it when the number is spelled in ENglish.
Or more literally, spelled numbers that contain the letter e are banned.
The American version of spelling numbers will be used here (as opposed to the British).
2,000,000,000 is two billion, not two milliard.
Only numbers less than one sextillion (1021) will be considered in/for this task.
This will allow optimizations to be used.
- Task
-
- show all eban numbers ≤ 1,000 (in a horizontal format), and a count
- show all eban numbers between 1,000 and 4,000 (inclusive), and a count
- show a count of all eban numbers up and including 10,000
- show a count of all eban numbers up and including 100,000
- show a count of all eban numbers up and including 1,000,000
- show a count of all eban numbers up and including 10,000,000
- show all output here.
- See also
-
- The MathWorld entry: [eban numbersl.
- The OEIS entry: [A6933, eban numbers].
Perl 6
<lang perl6>use Lingua::EN::Numbers::Cardinal;
sub eban (@seq) { (@seq».Int).map: { next if .&cardinal.contains('e'); $_ } }
sub comma { $^i.flip.comb(3).join(',').flip }
my @eban = flat ((1 .. 100),).map: *.&eban;
my @orders = ( ( 1e3, 2e3 ... 9e3 ),
( 1e4, 2e4 ... 9e4 ), ( 1e6, 2e6 ... 9e6 ), ( 1e7, 2e7 ... 9e7 ), ( 1e9, 2e9 ... 9e9 ), ).map: *.&eban;
for @orders -> @order {
my @these; for @order { my @extend = flat $_, flat @eban X+ $_; @these.append: @extend; } @eban.append: @these
}
my $k = @eban.first( * > 100, :k ); put @eban[^$k]; say "Up to 100: ", +@eban[^$k]; say '=' x 40;
my $b = @eban.first( * >= 1000, :k ); my $f = @eban.first( * >= 4000, :k ); put @eban[$b .. $f]; say "From 1,000 to 4,000: ", +@eban[$b .. $f]; say '=' x 40;
for (1e4, 1e5, 1e6, 1e7, 1e9)».Int
-> $e { my $f = @eban.first( * >= $e, :k ); say "Up to {comma $e}: ", +@eban[^$f]; say '=' x 40;
}</lang>
- Output:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 Up to 100: 19 ======================================== 2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 From 1,000 to 4,000: 21 ======================================== Up to 10,000: 79 ======================================== Up to 100,000: 399 ======================================== Up to 1,000,000: 399 ======================================== Up to 10,000,000: 1599 ======================================== Up to 1,000,000,000: 7999 ========================================
REXX
Programming note: REXX has no shortcuts for if statements, so the multiple if statements weren't combined into one. <lang rexx>/*REXX program to display eban numbers (those that don't have an "e" their English name)*/ numeric digits 20 /*support some gihugic numbers for pgm.*/ parse arg $ /*obtain optional arguments from the cL*/ if $= then $= '1 1000 1000 4000 1 -10000 1 -100000 1 -1000000 1 -10000000'
do k=1 by 2 to words($) /*step through the list of numbers. */ call banE word($, k), word($, k+1) /*process the numbers, from low──►high.*/ end /*k*/
exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ banE: procedure; parse arg x,y,_; z= reverse(x) /*obtain the number to be examined. */
tell= y>=0 /*Is HI non-negative? Display eban #s.*/ #= 0 /*the count of eban numbers (so far).*/ do j=x to abs(y) /*probably process a range of numbers. */ if hasE(j) then iterate /*determine if the number has an "e". */ #= # + 1 /*bump the counter of eban numbers. */ if tell then _= _ j /*maybe add to a list of eban numbers. */ end /*j*/ if _\== then say strip(_) /*display the list (if there is one). */ say; say # ' eban numbers found for: ' x " " y; say copies('═', 105) return
/*──────────────────────────────────────────────────────────────────────────────────────*/ hasE: procedure; parse arg x; z= reverse(x) /*obtain the number to be examined. */
do k=1 by 3 /*while there're dec. digit to examine.*/ @= reverse( substr(z, k, 3) ) /*obtain 3 dec. digs (a period) from Z.*/ if @==' ' then return 0 /*we have reached the "end" of the num.*/ uni= right(@, 1) /*get units dec. digit of this period. */ if uni//2==1 then return 1 /*if an odd digit, then not an eban #. */ if uni==8 then return 1 /*if an eight, " " " " " */ tens=substr(@, 2, 1) /*get tens dec. digit of this period. */ if tens==1 then return 1 /*if teens, then not an eban #. */ if tens==2 then return 1 /*if twenties, " " " " " */ if tens>6 then return 1 /*if 70s, 80s, 90s, " " " " " */ hun= left(@, 1) /*get hundreds dec. dig of this period.*/ if hun==0 then iterate /*if zero, then there is more of number*/ if hun\==' ' then return 1 /*any hundrEd (not zero) has an "e". */ end /*k*/ /*A "period" is a group of 3 dec. digs */ return 0 /*in the number, grouped from the right*/</lang>
- output when using the default inputs:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 19 eban numbers found for: 1 1000 ═════════════════════════════════════════════════════════════════════════════════════════════════════════ 2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 21 eban numbers found for: 1000 4000 ═════════════════════════════════════════════════════════════════════════════════════════════════════════ 79 eban numbers found for: 1 -10000 ═════════════════════════════════════════════════════════════════════════════════════════════════════════ 399 eban numbers found for: 1 -100000 ═════════════════════════════════════════════════════════════════════════════════════════════════════════ 399 eban numbers found for: 1 -1000000 ═════════════════════════════════════════════════════════════════════════════════════════════════════════ 1599 eban numbers found for: 1 -10000000 ═════════════════════════════════════════════════════════════════════════════════════════════════════════