Created
March 7, 2023 03:27
-
-
Save gargeesuresh/1c4ff8389b89c43491c6bf6c5fe18ded to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # too hot | |
| def sum_of_n_numbers(n): | |
| return reduce(lambda acc, x: acc + x, map(lambda x: x[1], filter(lambda x: x[0] % 2 == 0, zip(range(1, n+1), sum_of_n_numbers(n-1) if n > 1 else []))), 0) | |
| # too cold | |
| def sum_of_n_numbers(n): | |
| total = 0 | |
| for i in range(1, n+1): | |
| total += i | |
| return total | |
| # just right | |
| def sum_of_n_numbers(n): | |
| return n * (n + 1) // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment