diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2019-09-28 15:12:09 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2019-09-28 15:12:09 +0200 |
| commit | 62a4ee40095accc6c18ed726eb633cfce7d5ca7e (patch) | |
| tree | d62d7b86e365eea8e2b4b291a504fc94873f457e /challenge-027 | |
| parent | 126470a354832f75436397a2b0dd960a518ad84b (diff) | |
| download | perlweeklychallenge-club-62a4ee40095accc6c18ed726eb633cfce7d5ca7e.tar.gz perlweeklychallenge-club-62a4ee40095accc6c18ed726eb633cfce7d5ca7e.tar.bz2 perlweeklychallenge-club-62a4ee40095accc6c18ed726eb633cfce7d5ca7e.zip | |
Moving files to right perl5 folder
Diffstat (limited to 'challenge-027')
| -rw-r--r-- | challenge-027/lubos-kolouch/perl5/ch-1.pl (renamed from challenge-027/lubos-kolouch/ch-1.pl) | 0 | ||||
| -rw-r--r-- | challenge-027/lubos-kolouch/perl5/ch-2.pl (renamed from challenge-027/lubos-kolouch/ch-2.pl) | 0 | ||||
| -rw-r--r-- | challenge-027/lubos-kolouch/python/ch27_1.py | 33 |
3 files changed, 33 insertions, 0 deletions
diff --git a/challenge-027/lubos-kolouch/ch-1.pl b/challenge-027/lubos-kolouch/perl5/ch-1.pl index 2e6c0130f9..2e6c0130f9 100644 --- a/challenge-027/lubos-kolouch/ch-1.pl +++ b/challenge-027/lubos-kolouch/perl5/ch-1.pl diff --git a/challenge-027/lubos-kolouch/ch-2.pl b/challenge-027/lubos-kolouch/perl5/ch-2.pl index d22227cda0..d22227cda0 100644 --- a/challenge-027/lubos-kolouch/ch-2.pl +++ b/challenge-027/lubos-kolouch/perl5/ch-2.pl diff --git a/challenge-027/lubos-kolouch/python/ch27_1.py b/challenge-027/lubos-kolouch/python/ch27_1.py new file mode 100644 index 0000000000..c1bf6589e4 --- /dev/null +++ b/challenge-027/lubos-kolouch/python/ch27_1.py @@ -0,0 +1,33 @@ +#! python3 + +import sys + +def get_intersection(points): + a = int(points[1]) + b = int(points[2]) + c = int(points[3]) + d = int(points[4]) + + p = int(points[5]) + q = int(points[6]) + r = int(points[7]) + s = int(points[8]) + + det = ( a - c ) * ( q - s ) - ( b - d ) * ( p - r ) + + if det == 0: + return 0 + + # Let's assume the lines are infinitely long + px = ( a * d - b * c ) * ( p - r ) - ( a - c ) * ( p * s - q * r ) / det; + py = ( a * d - b * c ) * ( q - s ) - ( b - d ) * ( p * s - q * r ) / det; + + return ( [ px, py ] ); + +if len(sys.argv) != 9: + print('Usage: ch-1.pl a b c d p q r s'); + sys.exit() + +result = get_intersection(sys.argv) + +print(result) |
