general: ex1: add solution
This commit is contained in:
parent
bbdfa71f82
commit
d535ee6e3f
20
general/ex1.py
Executable file
20
general/ex1.py
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
from typing import Iterator
|
||||||
|
|
||||||
|
|
||||||
|
def fibo() -> Iterator[int]:
|
||||||
|
a, b = 0, 1
|
||||||
|
while True:
|
||||||
|
yield a
|
||||||
|
a, b = b, a + b
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
even_fibo_numbers = (x for x in fibo() if x % 2 == 0)
|
||||||
|
print(sum(itertools.islice(even_fibo_numbers, 100)))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue