Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,18 @@
class Ref(object):
def __init__(self, value=None):
self.value = value
def harmonic_sum(i, lo, hi, term):
# term is passed by-name, and so is i
temp = 0
i.value = lo
while i.value <= hi: # Python "for" loop creates a distinct which
temp += term() # would not be shared with the passed "i"
i.value += 1 # Here the actual passed "i" is incremented.
return temp
i = Ref()
# note the correspondence between the mathematical notation and the
# call to sum it's almost as good as sum(1/i for i in range(1,101))
print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)

View file

@ -0,0 +1,5 @@
def harmonic_sum(i, lo, hi, term):
return sum(term() for i[0] in range(lo, hi + 1))
i = [0]
print(harmonic_sum(i, 1, 100, lambda: 1.0 / i[0]))

View file

@ -0,0 +1,5 @@
def harmonic_sum(i, lo, hi, term):
return sum(eval(term) for i[0] in range(lo, hi + 1))
i = [0]
print(harmonic_sum(i, 1, 100, "1.0 / i[0]"))