Eban numbers: Difference between revisions
Content added Content deleted
m (Updated description and link for Fōrmulæ solution) |
|||
Line 1,061: | Line 1,061: | ||
count = 7999</pre> |
count = 7999</pre> |
||
=={{header|jq}}== |
|||
'''Adapted from Julia and Wren''' |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' (*) |
|||
(*) gojq's memory requirements are rather extravagent and may prevent |
|||
completion of the task beyond 1E+7; the output shown below was |
|||
obtained using the C implementation of jq. |
|||
<lang jq># quotient and remainder |
|||
def quotient($a; $b; f; g): f = (($a/$b)|floor) | g = $a % $b; |
|||
def tasks: |
|||
[2, 1000, true], |
|||
[1000, 4000, true], |
|||
(1e4, 1e5, 1e6, 1e7, 1e8 | [2, ., false]) ; |
|||
def task: |
|||
def update(f): if (f >= 30 and f <= 66) then f %= 10 else . end; |
|||
tasks as $rg |
|||
| if $rg[0] == 2 |
|||
then "eban numbers up to and including \($rg[1]):" |
|||
else "eban numbers between \($rg[0]) and \($rg[1]) (inclusive):" |
|||
end, |
|||
( foreach (range( $rg[0]; 1 + $rg[1]; 2), null) as $i ( { count: 0 }; |
|||
.emit = false |
|||
| if $i == null then .total = .count |
|||
else quotient($i; 1e9; .b; .r) |
|||
| quotient(.r; 1e6; .m; .r) |
|||
| quotient(.r; 1e3; .t; .r) |
|||
| update(.m) | update(.t) | update(.r) |
|||
| if all(.b, .m, .t, .r; IN(0, 2, 4, 6)) |
|||
then .count += 1 |
|||
| if ($rg[2]) then .emit=$i else . end |
|||
else . |
|||
end |
|||
end; |
|||
if .emit then .emit else empty end, |
|||
if .total then "count = \(.count)\n" else empty end) ); |
|||
task</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 1E+4: |
|||
count = 79 |
|||
eban numbers up to and including 1E+5: |
|||
count = 399 |
|||
eban numbers up to and including 1E+6: |
|||
count = 399 |
|||
eban numbers up to and including 1E+7: |
|||
count = 1599 |
|||
eban numbers up to and including 1E+8: |
|||
count = 7999 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<lang Julia> |
<lang Julia> |