]> git.leopard-lacewing.eu Git - prjeul.git/commitdiff
func update
authortreecity <schaeferpm@gmail.com>
Fri, 6 Apr 2012 23:11:42 +0000 (01:11 +0200)
committertreecity <schaeferpm@gmail.com>
Fri, 6 Apr 2012 23:11:42 +0000 (01:11 +0200)
func.py [new file with mode: 0644]

diff --git a/func.py b/func.py
new file mode 100644 (file)
index 0000000..86edcdc
--- /dev/null
+++ b/func.py
@@ -0,0 +1,67 @@
+# Berechnet die Summe aller vielfachen von base bis max
+def summandielle(max,base=1):
+    max = int(max/base)*base
+    return max*(max+base)/(2*base)
+
+# Gibt die naechst kleine Fib zu max zurueck
+def fib(max):
+    a,b = 1,2
+    while b < max:
+        a,b = b,a+b
+    return a
+
+# Gibt die Liste aller Fib zur naechst kleineren Fib von max zurueck
+def fib2(max):
+    a = [1, 2]
+    i = 1;
+    while a[i] < max:
+        a.append(a[i] + a[i-1])
+        i = i+1
+    return a
+
+# Gibt die Summe aller geraden Fib zu max zurueck
+def fibS(max):
+    a,b = 1,2
+    sum = 0
+    while b < max:
+        a,b = b,a+b
+        if a%2 == 0:
+            sum = sum +a
+            
+    return sum
+# Gibt alle Primzahlen bis n zurueck
+def primes(n):
+    if n < 2:
+        return 0
+    p = range(1,n+1,2)
+    q = len(p);
+    p[0] = 2;
+    for k in range(3,int(n**.5+1),2):
+        if p[(k-1)/2]:
+            for i in range(((k*k-1)/2),q,k):
+                p[i] = 0
+    return filter(lambda x:x>0,p)
+
+# Gibt alle Primfaktoren bis von n zurueck
+def factor(n):
+    if n<4:
+        return []
+    p = primes(int(n**.5+1))
+    f = []
+    while n>1:
+        p = filter(lambda x:n%x==0,p)
+        if(p==[]):
+            f.append(n)
+            break
+        f[len(f):] = p
+        n = n/prod(p)
+    f.sort()
+    return f
+    
+# Multipliziert alle Werte aus liste seq auf
+def prod(seq):
+    return reduce(lambda x,y:x*y, seq, 1)
+
+# generiert Pyth tripel
+def pythtrip(u,v):
+    return [u*u-v*v, 2*u*v, u*u+v*v]
\ No newline at end of file