Spaces:
Runtime error
Runtime error
Download examples/euler2.py from percepta-ai/spotlight-vm: direct link, hf CLI and curl.
- Browser
- Download file 494 Bytes
-
https://huggingface.co/spaces/percepta-ai/spotlight-vm/resolve/main/examples/euler2.py
- Command line
-
hf download hf://spaces/percepta-ai/spotlight-vm/examples/euler2.py
-
curl -L -o euler2.py https://huggingface.co/spaces/percepta-ai/spotlight-vm/resolve/main/examples/euler2.py
494 Bytes
| # https://projecteuler.net/problem=2 | |
| # Sum the even Fibonacci terms not exceeding 4,000,000. | |
| # Recursive function calling, generators and Python idioms | |
| def fib(): | |
| a, b = 1, 2 | |
| while True: | |
| yield a | |
| a, b = b, a + b | |
| def evens(it): | |
| for x in it: | |
| if x % 2 == 0: | |
| yield x | |
| def upto(limit, it): | |
| for x in it: | |
| if x > limit: | |
| return | |
| yield x | |
| def euler2(limit=4000000): | |
| return sum(evens(upto(limit, fib()))) | |
| print(euler2()) | |