Saturday, 29 December 2018

Competitive Helper - New Function

I've added small, but useful function to the  https://github.com/lion137/Competitive-Helper . It computes, within the range, any, well, lots of number series, like a Harmonic series or so. Works only on floats, but this is just a helper, basically to sanity check the work. Usage in the readme. A small example, also, here:
1
2
3
4
5
6
7
8
9
def factorial(n):
 if n == 0: return 1
 s = 1
 while n > 0:
  s *= n
  n -= 1
 return s

print(reduce_series(add, lambda n: n / (factorial(n)), 0, 7))

Supplying add as an operator and n / n! function from 0 to, let's say, seven, we have a Euler number.
Enjoy!

No comments: