Eban numbers: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 37:
{{trans|Nim}}
 
<langsyntaxhighlight lang="11l">F iseban(n)
I n == 0
R 0B
Line 64:
I iseban(i)
count++
print("\nNumber of eban numbers up to and including #8: #4".format(maxn, count))</langsyntaxhighlight>
 
{{out}}
Line 84:
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">(*
Quickly generate all the (positive) eban numbers up to and including the
specified end number, then lose those before the start number.
Line 199:
end runTask
 
runTask()</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"19 eban numbers between 0 and 1,000:
2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66
21 between 1,000 and 4,000:
Line 211:
1599 up to and including 10,000,000
16 between 66,066,066,020 and 1,000,000,000,000:
6.606606603E+10, 6.6066066032E+10, 6.6066066034E+10, 6.6066066036E+10, 6.606606604E+10, 6.6066066042E+10, 6.6066066044E+10, 6.6066066046E+10, 6.606606605E+10, 6.6066066052E+10, 6.6066066054E+10, 6.6066066056E+10, 6.606606606E+10, 6.6066066062E+10, 6.6066066064E+10, 6.6066066066E+10"</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">eban_numbers(min, max, show:=0){
counter := 0, output := ""
i := min
Line 238:
}
return min "-" max " : " output " Count = " counter
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">MsgBox, 262144, , % eban_numbers(0, 1000, 1)
MsgBox, 262144, , % eban_numbers(1000, 4000, 1)
MsgBox, 262144, , % eban_numbers(0, 10000)
MsgBox, 262144, , % eban_numbers(0, 100000)
MsgBox, 262144, , % eban_numbers(0, 1000000)
MsgBox, 262144, , % eban_numbers(0, 100000000)</langsyntaxhighlight>
{{out}}
<pre>2-1000 : 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 Count = 19
Line 255:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f EBAN_NUMBERS.AWK
# converted from FreeBASIC
Line 292:
return(n == 0 || n == 2 || n == 4 || n == 6)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 306:
=={{header|C}}==
{{trans|D}}
<langsyntaxhighlight lang="c">#include "stdio.h"
#include "stdbool.h"
 
Line 369:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 398:
=={{header|C sharp|C#}}==
{{trans|D}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace EbanNumbers {
Line 460:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 490:
=={{header|C++}}==
{{trans|D}}
<langsyntaxhighlight lang="cpp">#include <iostream>
 
struct Interval {
Line 545:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 574:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">eban = cluster is numbers
rep = null
Line 667:
if nextmagn>maxmagn then break end
end
end start_up </langsyntaxhighlight>
{{out}}
<pre> 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
Line 687:
=={{header|D}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="d">import std.stdio;
 
struct Interval {
Line 740:
writeln;
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to an including 1000:
Line 770:
=={{header|Factor}}==
{{trans|Julia}}
<langsyntaxhighlight lang="factor">USING: arrays formatting fry io kernel math math.functions
math.order math.ranges prettyprint sequences ;
 
Line 784:
 
1 1000 1000 4000 [ .eban-range ] 2bi@
4 9 [a,b] [ [ 1 10 ] dip ^ .eban-count ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 798:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
' Eban_numbers
' Un número eban es un número que no tiene la letra e cuando el número está escrito en inglés.
Line 857:
Print "Run time: " & (tiempo) & " seconds."
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 895:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 956:
fmt.Println("count =", count, "\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 989:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">class Main {
private static class Range {
int start
Line 1,050:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Same as the Java entry</pre>
Line 1,056:
=={{header|Haskell}}==
{{trans|Julia}}
<langsyntaxhighlight lang="haskell">{-# LANGUAGE NumericUnderscores #-}
import Data.List (intercalate)
import Text.Printf (printf)
Line 1,088:
, 100_000_000
, 1_000_000_000 ]
r = ((,) <$> thousands . length <*> show) . filter isEban</langsyntaxhighlight>
{{out}}
<pre>
Line 1,106:
 
=={{header|J}}==
<syntaxhighlight lang="j">
<lang J>
Filter =: (#~`)(`:6)
 
Line 1,131:
1e6 399
1e7 1599
</syntaxhighlight>
</lang>
 
=={{header|Java}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="java">import java.util.List;
 
public class Main {
Line 1,195:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000
Line 1,231:
completion of the task beyond 1E+7; the output shown below was
obtained using the C implementation of jq.
<langsyntaxhighlight lang="jq"># quotient and remainder
def quotient($a; $b; f; g): f = (($a/$b)|floor) | g = $a % $b;
 
Line 1,263:
if .total then "count = \(.count)\n" else empty end) );
 
task</langsyntaxhighlight>
{{out}}
<pre>
Line 1,328:
</pre>
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
function iseban(n::Integer)
b, r = divrem(n, oftype(n, 10 ^ 9))
Line 1,349:
println("eban numbers up to and including 100000000: ", count(iseban, 1:100000000))
println("eban numbers up to and including 1000000000: ", count(iseban, 1:1000000000))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,365:
=={{header|Kotlin}}==
{{trans|Go}}
<langsyntaxhighlight lang="scala">// Version 1.3.21
 
typealias Range = Triple<Int, Int, Boolean>
Line 1,412:
println("count = $count\n")
}
}</langsyntaxhighlight>
 
{{output}}
Line 1,421:
=={{header|Lua}}==
{{trans|lang}}
<langsyntaxhighlight lang="lua">function makeInterval(s,e,p)
return {start=s, end_=e, print_=p}
end
Line 1,473:
end
 
main()</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 1,499:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[ZeroTwoFourSixQ, EbanNumbers]
ZeroTwoFourSixQ[n_Integer] := (n == 0 || n == 2 || n == 4 || n == 6)
EbanNumbers[min_, max_, show : (False | True)] :=
Line 1,534:
EbanNumbers[0, 10^5, False]
EbanNumbers[0, 10^6, False]
EbanNumbers[0, 10^7, False]</langsyntaxhighlight>
{{out}}
<pre>0-1000: 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 count = 19
Line 1,546:
===Exhaustive search===
{{trans|Julia}}
<langsyntaxhighlight lang="nim">import strformat
 
proc iseban(n: int): bool =
Line 1,600:
if iseban(i):
inc count
echo &"\nNumber of eban numbers up to and including {100000000:8}: {count:4}"</langsyntaxhighlight>
 
{{out}}
Line 1,621:
===Algorithmic computation===
{{trans|Phix}}
<langsyntaxhighlight Nimlang="nim">import math, strutils, strformat
 
#---------------------------------------------------------------------------------------------------
Line 1,664:
echo fmt"ebanCount(10^{i}): {ebanCount(i)}"
echo ""
echo fmt"Time: {getTime() - t0}"</langsyntaxhighlight>
 
{{out}}
Line 1,697:
===Exhaustive search===
A couple of 'e'-specific optimizations keep the running time reasonable.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,730:
my $n = + grep { $_ <= 10**$exp } @OK;
printf "Number of eban numbers and %10s: %d\n", comma(10**$exp), $n;
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 1,746:
Alternately, a partial translation of Raku. Does not need to actually generate the e-ban numbers to count them. Display counts up to 10**21.
 
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use bigint;
Line 1,821:
printf "Up to and including %23s: %s\n", lc(num2word(10**$exp)), comma($nu);
}
}</langsyntaxhighlight>
<pre>============= e-ban: =============
e-ban numbers up to 1000: 19
Line 1,854:
=={{header|Phix}}==
Why count when you can calculate?
<!--<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;">count_eban</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p10</span><span style="color: #0000FF;">)</span>
Line 1,893:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,926:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de _eban? (N)
(let
(B (/ N 1000000000)
Line 1,982:
(prinl)
(prinl "eban numbers up to an including 10000000:")
(prinl "count: " (car (eban 10000000)))</langsyntaxhighlight>
{{out}}
<pre>
Line 2,007:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
# Use inflect
 
Line 2,132:
print(" ")
print("Run time in seconds: "+str(after - before))
</syntaxhighlight>
</lang>
 
Output:
Line 2,200:
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest.
 
<syntaxhighlight lang="raku" perl6line>use Lingua::EN::Numbers;
 
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } }
Line 2,271:
printf "Up to and including %{$s}s: %s\n", cardinal(10**($c+1)), comma(@counts[$c]);
}
}</langsyntaxhighlight>
{{out}}
<pre>============= e-ban: =============
Line 2,372:
=={{header|REXX}}==
Programming note: &nbsp; REXX has no shortcuts for &nbsp; '''if''' &nbsp; statements, so the multiple &nbsp; '''if''' &nbsp; statements weren't combined into one.
<langsyntaxhighlight 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*/
Line 2,409:
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*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 2,436:
=={{header|Ruby}}==
{{trans|C#}}
<langsyntaxhighlight lang="ruby">def main
intervals = [
[2, 1000, true],
Line 2,492:
end
 
main()</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 2,522:
=={{header|Scala}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">object EbanNumbers {
 
class ERange(s: Int, e: Int, p: Boolean) {
Line 2,585:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to an including 1000
Line 2,614:
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
templates isEban
def number: $;
'$;' -> \(<'([246]|[3456][0246])(0[03456][0246])*'> $ !\) -> $number !
end isEban
</syntaxhighlight>
</lang>
 
Alternatively, if regex is not your thing, we can do it numerically, which actually runs faster
<langsyntaxhighlight lang="tailspin">
templates isEban
def number: $;
Line 2,629:
when <?($ mod 1000 <=0|=2|=4|=6|30..66?($ mod 10 <=0|=2|=4|=6>)>)> do $ ~/ 1000 -> #
end isEban
</syntaxhighlight>
</lang>
 
Either version is called by the following code
<langsyntaxhighlight lang="tailspin">
def small: [1..1000 -> isEban];
$small -> !OUT::write
Line 2,662:
 
' -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,686:
=={{header|Visual Basic .NET}}==
{{trans|D}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Structure Interval
Line 2,756:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 2,786:
=={{header|Vlang}}==
{{trans|go}}
<langsyntaxhighlight lang="vlang">struct Range {
start i64
end i64
Line 2,843:
println("count = $count\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,876:
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight lang="ecmascript">var rgs = [
[2, 1000, true],
[1000, 4000, true],
Line 2,918:
if (rg[2]) System.print()
System.print("count = %(count)\n")
}</langsyntaxhighlight>
 
{{out}}
Line 2,951:
=={{header|Yabasic}}==
{{trans|Go}}
<langsyntaxhighlight Yabasiclang="yabasic">data 2, 100, true
data 1000, 4000, true
data 2, 1e4, false
Line 2,994:
if printable Print
Print "count = ", count, "\n"
loop</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Go}}
<langsyntaxhighlight lang="zkl">rgs:=T( T(2, 1_000, True), // (start,end,print)
T(1_000, 4_000, True),
T(2, 1e4, False), T(2, 1e5, False), T(2, 1e6, False), T(2, 1e7, False),
Line 3,025:
println("count = %,d\n".fmt(count));
}
fcn magic(z){ z.isEven and z<=6 }</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">
10,333

edits