diff options
| author | chirvasitua <chirvasitua@gmail.com> | 2021-07-26 12:01:54 -0400 |
|---|---|---|
| committer | chirvasitua <chirvasitua@gmail.com> | 2021-07-26 12:01:54 -0400 |
| commit | fa7c07153cf957f1f7b215f5b8c8ab975436d7b9 (patch) | |
| tree | 988bdcc7a92d93590728cd4ecf6eebeff554dcda | |
| parent | 4231c2f762b397e1cacd2cb7e3c2799254fcc1a4 (diff) | |
| download | perlweeklychallenge-club-fa7c07153cf957f1f7b215f5b8c8ab975436d7b9.tar.gz perlweeklychallenge-club-fa7c07153cf957f1f7b215f5b8c8ab975436d7b9.tar.bz2 perlweeklychallenge-club-fa7c07153cf957f1f7b215f5b8c8ab975436d7b9.zip | |
1st commit on 123_python
| -rwxr-xr-x | challenge-123/stuart-little/python/ch-1.py | 21 | ||||
| -rwxr-xr-x | challenge-123/stuart-little/python/ch-2.py | 17 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-123/stuart-little/python/ch-1.py b/challenge-123/stuart-little/python/ch-1.py new file mode 100755 index 0000000000..40fec4185e --- /dev/null +++ b/challenge-123/stuart-little/python/ch-1.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# run <script> <number $n> to return the first $n ugly numbers + +import sys + +memo = set([1,2,3,5]) +def smth5p(n): + if n in memo: + return True + for prm in [2,3,5]: + if (n % prm == 0) and int(n/prm) in memo: + memo.add(n) + return True + return False +count,nr=0,0 +while count < int(sys.argv[1]): + nr+=1 + if smth5p(nr): + print(nr) + count+=1 diff --git a/challenge-123/stuart-little/python/ch-2.py b/challenge-123/stuart-little/python/ch-2.py new file mode 100755 index 0000000000..5217e7dc6e --- /dev/null +++ b/challenge-123/stuart-little/python/ch-2.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +# run <script> <x1 y1 x2 y2 ..> + +from collections import Counter +import sys + +def sqDist(coords): + return (coords[2]-coords[0])**2 + (coords[3]-coords[1])**2 + +def sqDistHash(coords): + return Counter([sqDist([coords[ix] for ix in [2*i,2*i+1,2*j,2*j+1]]) for i in range(3) for j in range(i+1,4)]) + +def isSq(coords): + return sorted(dict(sqDistHash(coords)).values()) == [2,4] + +print(1 if isSq([float(x) for x in sys.argv[1:9]]) else 0) |
