Eban numbers: Difference between revisions

eban numbers task written in Odin
(eban numbers task written in Odin)
Line 1,685:
Number of eban numbers up to and including 10000000: 1599
</pre>
 
===Algorithmic computation===
{{trans|Phix}}
Line 1,760 ⟶ 1,759:
 
Time: 189 microseconds and 491 nanoseconds</pre>
 
=={{header|Odin}}==
<syntaxhighlight lang="Go">
package eban_numbers
/* imports */
import "core:fmt"
/* globals */
Range :: struct {
start: i32,
end: i32,
print: bool,
}
printcounter: i32 = 0
/* main block */
main :: proc() {
rgs := [?]Range{
{2, 1000, true},
{1000, 4000, true},
{2, 1e4, false},
{2, 1e5, false},
{2, 1e6, false},
{2, 1e7, false},
{2, 1e8, false},
{2, 1e9, false},
}
for rg in rgs {
if rg.start == 2 {
fmt.printf("eban numbers up to and including %d:\n", rg.end)
} else {
fmt.printf("eban numbers between %d and %d (inclusive):\n", rg.start, rg.end)
}
count := i32(0)
for i := rg.start; i <= i32(rg.end); i += i32(2) {
b := i / 1000000000
r := i % 1000000000
m := r / 1000000
r = i % 1000000
t := r / 1000
r %= 1000
if m >= 30 && m <= 66 {
m %= 10
}
if t >= 30 && t <= 66 {
t %= 10
}
if r >= 30 && r <= 66 {
r %= 10
}
if b == 0 || b == 2 || b == 4 || b == 6 {
if m == 0 || m == 2 || m == 4 || m == 6 {
if t == 0 || t == 2 || t == 4 || t == 6 {
if r == 0 || r == 2 || r == 4 || r == 6 {
if rg.print {
fmt.printf("%d ", i)
}
count += 1
}
}
}
}
}
if rg.print {
fmt.println()
}
fmt.println("count =", count, "\n")
}
}
</syntaxhighlight>
{{out}}
<pre>
eban numbers up to and including 1000:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
count = 19
 
eban numbers between 1000 and 4000 (inclusive):
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
count = 21
 
eban numbers up to and including 10000:
count = 79
 
eban numbers up to and including 100000:
count = 399
 
eban numbers up to and including 1000000:
count = 399
 
eban numbers up to and including 10000000:
count = 1599
 
eban numbers up to and including 100000000:
count = 7999
 
eban numbers up to and including 1000000000:
count = 7999
</pre>
 
=={{header|Perl}}==
37

edits