Eban numbers: Difference between revisions
Content added Content deleted
Line 1,804: | Line 1,804: | ||
═════════════════════════════════════════════════════════════════════════════════════════════════════════ |
═════════════════════════════════════════════════════════════════════════════════════════════════════════ |
||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
|||
{{trans|C#}} |
|||
<lang ruby>def main |
|||
intervals = [ |
|||
[2, 1000, true], |
|||
[1000, 4000, true], |
|||
[2, 10000, false], |
|||
[2, 100000, false], |
|||
[2, 1000000, false], |
|||
[2, 10000000, false], |
|||
[2, 100000000, false], |
|||
[2, 1000000000, false] |
|||
] |
|||
for intv in intervals |
|||
(start, ending, display) = intv |
|||
if start == 2 then |
|||
print "eban numbers up to and including %d:\n" % [ending] |
|||
else |
|||
print "eban numbers between %d and %d (inclusive):\n" % [start, ending] |
|||
end |
|||
count = 0 |
|||
for i in (start .. ending).step(2) |
|||
b = (i / 1000000000).floor |
|||
r = (i % 1000000000) |
|||
m = (r / 1000000).floor |
|||
r = (r % 1000000) |
|||
t = (r / 1000).floor |
|||
r = (r % 1000) |
|||
if m >= 30 and m <= 66 then |
|||
m = m % 10 |
|||
end |
|||
if t >= 30 and t <= 66 then |
|||
t = t % 10 |
|||
end |
|||
if r >= 30 and r <= 66 then |
|||
r = r % 10 |
|||
end |
|||
if b == 0 or b == 2 or b == 4 or b == 6 then |
|||
if m == 0 or m == 2 or m == 4 or m == 6 then |
|||
if t == 0 or t == 2 or t == 4 or t == 6 then |
|||
if r == 0 or r == 2 or r == 4 or r == 6 then |
|||
if display then |
|||
print ' ', i |
|||
end |
|||
count = count + 1 |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
if display then |
|||
print "\n" |
|||
end |
|||
print "count = %d\n\n" % [count] |
|||
end |
|||
end |
|||
main()</lang> |
|||
{{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|Scala}}== |
=={{header|Scala}}== |