aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsangeet <sangeet.kar@gmail.com>2020-06-02 09:05:01 +0000
committersangeet <sangeet.kar@gmail.com>2020-06-02 09:05:01 +0000
commit3f605af6c19ce1dc8ba98d73a4c33ee779aab2c7 (patch)
tree80b3d6d5732022df44082443c882b902ded8cddd
parent35c76b94e7c2e784a2b94a01e07d79bb8c603978 (diff)
downloadperlweeklychallenge-club-3f605af6c19ce1dc8ba98d73a4c33ee779aab2c7.tar.gz
perlweeklychallenge-club-3f605af6c19ce1dc8ba98d73a4c33ee779aab2c7.tar.bz2
perlweeklychallenge-club-3f605af6c19ce1dc8ba98d73a4c33ee779aab2c7.zip
Ch-1 and Ch-2 in python
-rwxr-xr-xchallenge-063/sangeet-kar/python/ch-1.py12
-rwxr-xr-xchallenge-063/sangeet-kar/python/ch-2.py16
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-063/sangeet-kar/python/ch-1.py b/challenge-063/sangeet-kar/python/ch-1.py
new file mode 100755
index 0000000000..0817cecb17
--- /dev/null
+++ b/challenge-063/sangeet-kar/python/ch-1.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+
+import re
+
+def last_word(string, regex):
+ return next((word for word in reversed(string.split()) if re.search(regex, word)), None)
+
+assert last_word(' hello world', r"[ea]l") == 'hello'
+assert last_word("Don't match too much, Chet!", re.compile(r"ch.t", re.I)) == 'Chet!'
+assert last_word("spaces in regexp won't match", r"in re") == None
+assert last_word( ' '.join(str(x) for x in range(1, 1000000)), r"^(3.*?){3}") == '399933'
+print("All tests passed")
diff --git a/challenge-063/sangeet-kar/python/ch-2.py b/challenge-063/sangeet-kar/python/ch-2.py
new file mode 100755
index 0000000000..af0d5c6382
--- /dev/null
+++ b/challenge-063/sangeet-kar/python/ch-2.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+import sys
+from itertools import count
+
+def rot(string, n=1):
+ return string[n:] + string[:n]
+
+inp = sys.argv[1] if len(sys.argv) > 1 else 'xyxx'
+
+tmp = inp
+for i in count(1):
+ tmp = rot(tmp, i % len(inp))
+ if tmp == inp:
+ print(i)
+ break