aboutsummaryrefslogtreecommitdiff
path: root/challenge-207/sgreen/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-207/sgreen/python')
-rwxr-xr-xchallenge-207/sgreen/python/ch-1.py17
-rwxr-xr-xchallenge-207/sgreen/python/ch-2.py24
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-207/sgreen/python/ch-1.py b/challenge-207/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..dd6a15c15a
--- /dev/null
+++ b/challenge-207/sgreen/python/ch-1.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+
+def main(words):
+ # Define the regular expression that makes up a single line on a keyboard
+ r = '^(?:[qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$'
+
+ # Find all words that match the pattern, and print it
+ matched_words = [w for w in words if re.search(r, w, re.IGNORECASE)]
+ print('(' + ','.join(f'"{w}"' for w in matched_words) + ')')
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/challenge-207/sgreen/python/ch-2.py b/challenge-207/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..e76b64c03f
--- /dev/null
+++ b/challenge-207/sgreen/python/ch-2.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ h_index = 0
+
+ for i in range(1, len(n)+1):
+ # Count the number of items that are >= i
+ count = sum(1 for x in n if x >= i)
+ if count >= i:
+ h_index = i
+ else:
+ # No point trying any more, as it will be False.
+ break
+
+ print(h_index)
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)