general: ex1: add solution

This commit is contained in:
Bruno BELANYI 2022-11-21 16:11:39 +01:00
parent bbdfa71f82
commit d535ee6e3f

20
general/ex1.py Executable file
View 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()