fork download
  1. #!/usr/bin/env python3
  2.  
  3. ### 余再帰
  4. def unfoldr(f):
  5. def wrapper(seed):
  6. acc = []
  7. while True:
  8. match f(seed):
  9. case a, b:
  10. acc.append(a)
  11. seed = b
  12. case None:
  13. return acc
  14. return wrapper
  15.  
  16. @unfoldr
  17. def d2b_engine(target):
  18. return None if target == 0 else (target % 2, target // 2)
  19.  
  20. def dec2bin(target):
  21. return [i == 1 for i in reversed(d2b_engine(target))]
  22.  
  23. if __name__ == '__main__':
  24. print(dec2bin(26))
  25.  
  26.  
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 8
    match f(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 8
    match f(seed):
          ^
SyntaxError: invalid syntax

stdout
Standard output is empty