Created
March 30, 2018 11:28
-
-
Save jan-matejka/5a0ca30359c7399877f4db1fda5f0f50 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
#!/usr/bin/env python | |
import sys | |
from math import sqrt | |
from collections import namedtuple | |
Input = namedtuple('Input', ['x', 'k', 'n']) | |
def logseq(x, k, n): | |
if n == 0: | |
return [float(x)] | |
else: | |
accum = logseq(x, k, n-1) | |
a = accum[-1] | |
accum.append(k * a * (1 - a)) | |
return accum | |
def _read_input(): | |
if len(sys.argv) == 1: | |
x = input("Dej mi x:") | |
k = input("Dej mi k:") | |
n = input("Dej mi n:") | |
i = Input(x, k, n) | |
else: | |
x = sys.argv[1] | |
k = sys.argv[2] | |
n = sys.argv[3] | |
i = Input(x, k, n) | |
i = Input(float(i.x), float(i.k), int(i.n)) | |
assert i.x >= 0 | |
assert i.k >= 0 | |
assert i.n >= 0 | |
return i | |
def main(): | |
i = _read_input() | |
xs = logseq(i.x, i.k, i.n) | |
avg = sum(xs) / float(len(xs)) | |
devs = [x - avg for x in xs] | |
for x in xs: | |
print(x) | |
print("\nPrumer: ", avg) | |
print("Prumerna absolutni odchylka: ", sum(devs)/float(len(devs))) | |
print("Smerodatna odchylka: ", (sqrt((sum(devs)**2) / float(len(devs))))) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment