From 068ea3d52d6d7e19ec6607957dc0146587e31af6 Mon Sep 17 00:00:00 2001 From: marekplochow Date: Wed, 8 Jun 2016 18:09:05 +0200 Subject: [PATCH 1/4] zadania domowe 1-5 --- solution/solution.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ solution/test.py | 17 +++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 solution/solution.py create mode 100644 solution/test.py diff --git a/solution/solution.py b/solution/solution.py new file mode 100644 index 0000000..ac5e74d --- /dev/null +++ b/solution/solution.py @@ -0,0 +1,60 @@ +import numpy as np +import sys +from math import sqrt, fabs + + +def Newton(n ,m): + def silnia(x): + a = 1 + for i in range(2, x + 1): + a *= i + return a + + return silnia(n ) /silnia(m ) /silnia( n -m) + + +def Pascal(n): + li = np.array([[0 for i in range(j+1)] for j in range(n)]) + for i in range(n): + li[i][0] = 1 + li[i][i] = 1 + if i>1: + for j in range(i-1): + li[i][j+1]=li[i-1][j] + li[i-1][j+1] + return li + +def LotOfHash(n): + li = Pascal(n) + for i in li: + for j in i: + if j%2 == 1: + sys.stdout.write("#") + else: + sys.stdout.write(" ") + print"" + +def PowerModulo(a,b,n): + w1 = a**b + w2 = w1%n + print w2 + +def Intersect((x1,y1,r1),(x2,y2,r2)): + w =[] + e = x2 - x1 + f = y2 - y1 + p = sqrt(e ** 2 + f ** 2) #odleglosc miedzy srodkami okregow + k = (p ** 2 + r1 ** 2 - r2 ** 2) / (2*p) + if p>r1+r1 or p Date: Wed, 8 Jun 2016 18:09:05 +0200 Subject: [PATCH 2/4] zadania domowe 1-5 --- solution/solution.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ solution/test.py | 17 +++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 solution/solution.py create mode 100644 solution/test.py diff --git a/solution/solution.py b/solution/solution.py new file mode 100644 index 0000000..ac5e74d --- /dev/null +++ b/solution/solution.py @@ -0,0 +1,60 @@ +import numpy as np +import sys +from math import sqrt, fabs + + +def Newton(n ,m): + def silnia(x): + a = 1 + for i in range(2, x + 1): + a *= i + return a + + return silnia(n ) /silnia(m ) /silnia( n -m) + + +def Pascal(n): + li = np.array([[0 for i in range(j+1)] for j in range(n)]) + for i in range(n): + li[i][0] = 1 + li[i][i] = 1 + if i>1: + for j in range(i-1): + li[i][j+1]=li[i-1][j] + li[i-1][j+1] + return li + +def LotOfHash(n): + li = Pascal(n) + for i in li: + for j in i: + if j%2 == 1: + sys.stdout.write("#") + else: + sys.stdout.write(" ") + print"" + +def PowerModulo(a,b,n): + w1 = a**b + w2 = w1%n + print w2 + +def Intersect((x1,y1,r1),(x2,y2,r2)): + w =[] + e = x2 - x1 + f = y2 - y1 + p = sqrt(e ** 2 + f ** 2) #odleglosc miedzy srodkami okregow + k = (p ** 2 + r1 ** 2 - r2 ** 2) / (2*p) + if p>r1+r1 or p Date: Wed, 29 Jun 2016 01:35:21 +0200 Subject: [PATCH 3/4] zadania domowe 1-5 --- .idea/vcs.xml | 6 ++++++ .travis.yml | 2 +- solution.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 17 +++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 solution.py create mode 100644 test.py diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ec3e6cd..1a4d2bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python before_install: - git clone https://github.com/$TRAVIS_REPO_SLUG.git original - - rm -rf .test; mv original/.test .test + - install: - .test/install script: diff --git a/solution.py b/solution.py new file mode 100644 index 0000000..ac5e74d --- /dev/null +++ b/solution.py @@ -0,0 +1,60 @@ +import numpy as np +import sys +from math import sqrt, fabs + + +def Newton(n ,m): + def silnia(x): + a = 1 + for i in range(2, x + 1): + a *= i + return a + + return silnia(n ) /silnia(m ) /silnia( n -m) + + +def Pascal(n): + li = np.array([[0 for i in range(j+1)] for j in range(n)]) + for i in range(n): + li[i][0] = 1 + li[i][i] = 1 + if i>1: + for j in range(i-1): + li[i][j+1]=li[i-1][j] + li[i-1][j+1] + return li + +def LotOfHash(n): + li = Pascal(n) + for i in li: + for j in i: + if j%2 == 1: + sys.stdout.write("#") + else: + sys.stdout.write(" ") + print"" + +def PowerModulo(a,b,n): + w1 = a**b + w2 = w1%n + print w2 + +def Intersect((x1,y1,r1),(x2,y2,r2)): + w =[] + e = x2 - x1 + f = y2 - y1 + p = sqrt(e ** 2 + f ** 2) #odleglosc miedzy srodkami okregow + k = (p ** 2 + r1 ** 2 - r2 ** 2) / (2*p) + if p>r1+r1 or p Date: Wed, 29 Jun 2016 14:07:23 +0200 Subject: [PATCH 4/4] zadania domowe 1-5 --- solution.py | 13 +++++++++---- test.py | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/solution.py b/solution.py index ac5e74d..f6e0b18 100644 --- a/solution.py +++ b/solution.py @@ -36,7 +36,7 @@ def LotOfHash(n): def PowerModulo(a,b,n): w1 = a**b w2 = w1%n - print w2 + return w2 def Intersect((x1,y1,r1),(x2,y2,r2)): w =[] @@ -49,12 +49,17 @@ def Intersect((x1,y1,r1),(x2,y2,r2)): elif p==r1+r2 or p==fabs(r1-r2): #okregi styczne x = x1 + e*k / p + (f / p)*sqrt(r1 ** 2 - k ** 2) y = y1 + f*k / p - (e / p)*sqrt(r1 ** 2 - k ** 2) - w = [x,y] + p = (x,y) + w.append(p) else: #okregi przecinaja sie x01 = x1 + e * k / p + (f / p) * sqrt(r1 ** 2 - k ** 2) y01 = y1 + f * k / p - (e / p) * sqrt(r1 ** 2 - k ** 2) + p1 = (x01, y01) + w.append(p1) x02 = x1 + e * k / p - (f / p) * sqrt(r1 ** 2 - k ** 2) y02 = y1 + f * k / p + (e / p) * sqrt(r1 ** 2 - k ** 2) - w = [(x01,y01),(x02,y02)] - print w \ No newline at end of file + p2 = (x02, y02) + w.append(p2) + + return w \ No newline at end of file diff --git a/test.py b/test.py index 515bdd5..14ef263 100644 --- a/test.py +++ b/test.py @@ -7,11 +7,11 @@ print"" LotOfHash(6) print"" -PowerModulo(2,200,100) +print PowerModulo(2,200,100) print"" -Intersect( (0,0,5), (6,0,5) ) +print Intersect( (0,0,5), (6,0,5) ) # [ (3, 4), (3,-4) ] -Intersect( (0,0,5), (10,0,5) ) +print Intersect( (0,0,5), (10,0,5) ) # [ (5, 0) ] -Intersect( (0,0,5), (15,0,5) ) +print Intersect( (0,0,5), (15,0,5) ) # [ ]