fork download
  1. #!/usr/bin/env python3
  2.  
  3. ### 余再帰
  4. class unfoldr:
  5. def __init__(self, f, seed):
  6. self.f = f
  7. self.seed = seed
  8. def __iter__(self):
  9. return self
  10. def __next__(self):
  11. match self.f(self.seed):
  12. case a, b:
  13. self.seed = b
  14. return a
  15. case None:
  16. raise StopIteration
  17. def __reversed__(self):
  18. return reversed(self)
  19.  
  20. def primes():
  21. yield 2
  22. for i in filter(is_prime, unfoldr(lambda x: (x, x + 1), 3)):
  23. yield i
  24.  
  25. def is_prime(n):
  26. for i in primes():
  27. if i ** 2 > n:
  28. return True
  29. elif n % i == 0:
  30. return False
  31. else:
  32. continue
  33.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.9/py_compile.py", line 144, in compile
    code = loader.source_to_code(source_bytes, dfile or file,
  File "<frozen importlib._bootstrap_external>", line 918, in source_to_code
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "./prog.py", line 11
    match self.f(self.seed):
          ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.9/py_compile.py", line 150, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 11
    match self.f(self.seed):
          ^
SyntaxError: invalid syntax

stdout
Standard output is empty