Eban numbers: Difference between revisions
Content added Content deleted
(Added AppleScript.) |
|||
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|AppleScript}}== |
|||
<lang applescript>(* |
|||
This assumes either positive or negative integer input and treats 0 as "zero" rather than as "nought" or "nil". |
|||
Because of AppleScript's number precision at the time of writing, the range is limited to between > -10^15 and < 10^15. |
|||
*) |
|||
on isEban(n) |
|||
if (n < 2) then |
|||
if (n > -2) then return false |
|||
set n to -1 |
|||
end if |
|||
repeat 5 times -- Change to 7 times for > -10^21 to < 10^21. |
|||
set x to n mod 1000 |
|||
if ((x > 66) or (x mod 2 is 1) or ((x < 30) and (x > 6)) or (x mod 10 is 8)) then return false |
|||
set n to n div 1000 |
|||
if (n is 0) then return true |
|||
end repeat |
|||
return missing value -- Status unknown. Number out of range. |
|||
end isEban |
|||
-- Task code: |
|||
on runTask() |
|||
set output to {} |
|||
set astid to AppleScript's text item delimiters |
|||
set AppleScript's text item delimiters to ", " |
|||
set collector to {} |
|||
repeat with i from 0 to 1000 |
|||
if (isEban(i) is true) then set end of collector to i |
|||
end repeat |
|||
set end of output to ((count collector) as text) & " eban numbers between 0 and 1,000:" & linefeed & " " & collector |
|||
set collector to {} |
|||
repeat with i from 1000 to 4000 |
|||
if (isEban(i) is true) then set end of collector to i |
|||
end repeat |
|||
set end of output to ((count collector) as text) & " eban numbers between 1,000 and 4,000:" & linefeed & " " & collector |
|||
set counter to 0 |
|||
set landmarks to {10000, 100000, 1000000, 10000000} |
|||
repeat with i from 0 to 10000000 |
|||
if (isEban(i) is true) then set counter to counter + 1 |
|||
if (i mod 10000 is 0) then |
|||
repeat with j from 1 to 4 |
|||
if (item j of landmarks is i) then |
|||
set end of output to (counter as text) & " eban numbers up to and including " & ¬ |
|||
item j of {"10,000", "100,000", "1,000,000", "10,000,000"} |
|||
exit repeat |
|||
end if |
|||
end repeat |
|||
end if |
|||
end repeat |
|||
set AppleScript's text item delimiters to linefeed |
|||
set output to output as text |
|||
set AppleScript's text item delimiters to astid |
|||
return output |
|||
end runTask |
|||
runTask()</lang> |
|||
{{output}} |
|||
<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 eban numbers between 1,000 and 4,000: |
|||
2000, 2002, 2004, 2006, 2030, 2032, 2034, 2036, 2040, 2042, 2044, 2046, 2050, 2052, 2054, 2056, 2060, 2062, 2064, 2066, 4000 |
|||
79 eban numbers up to and including 10,000 |
|||
399 eban numbers up to and including 100,000 |
|||
399 eban numbers up to and including 1,000,000 |
|||
1599 eban numbers up to and including 10,000,000"</lang> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |