aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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