Content deleted Content added
Ronaldws r+d (talk | contribs) →Raku: Improved coding example. Tags: Mobile edit Mobile web edit |
mNo edit summary |
||
Line 309:
Fibonacci sequence with limit:
<syntaxhighlight lang="php">
function fibonacci(int $limit): generator
{
yield $a = $b = $i = 1;
Line 544:
def primes() -> Iterator[int]:
"""Generate prime numbers indefinitely as needed."""
yield 2
n = 3
Line 550 ⟶ 551:
# If dividing n by all the numbers in p, up to and including sqrt(n),
# produces a non-zero remainder then n is prime.
if all(n % f > 0 for f in itertools.takewhile(lambda f: f * f <= n, p)):
yield n
p.append(n)
|