aboutsummaryrefslogtreecommitdiff
path: root/challenge-280
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-10-14 16:04:15 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-10-14 16:04:15 +0100
commit4318c0c2d98fa2458684bb64dedb6c96f0837f85 (patch)
treeb895449172d9770a94d737e5388cd0d41e306cf2 /challenge-280
parent13976768df8eb3b957bb8b46ce68000fd2f9cc73 (diff)
downloadperlweeklychallenge-club-4318c0c2d98fa2458684bb64dedb6c96f0837f85.tar.gz
perlweeklychallenge-club-4318c0c2d98fa2458684bb64dedb6c96f0837f85.tar.bz2
perlweeklychallenge-club-4318c0c2d98fa2458684bb64dedb6c96f0837f85.zip
Add Python solution to challenge 280
Diffstat (limited to 'challenge-280')
-rw-r--r--challenge-280/paulo-custodio/python/ch-1.py31
-rw-r--r--challenge-280/paulo-custodio/python/ch-2.py33
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-280/paulo-custodio/python/ch-1.py b/challenge-280/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..4630c4d3b8
--- /dev/null
+++ b/challenge-280/paulo-custodio/python/ch-1.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+# Challenge 280
+#
+# Task 1: Twice Appearance
+# Submitted by: Mohammad Sajid Anwar
+# You are given a string, $str, containing lowercase English letters only.
+#
+# Write a script to print the first letter that appears twice.
+#
+# Example 1
+# Input: $str = "acbddbca"
+# Output: "d"
+# Example 2
+# Input: $str = "abccd"
+# Output: "c"
+# Example 3
+# Input: $str = "abcdabbb"
+# Output: "a"
+
+import sys
+
+def double_letter(s):
+ found = {}
+ for char in s:
+ if char in found:
+ return char
+ found[char] = True
+ return ""
+
+print(double_letter(sys.argv[1]))
diff --git a/challenge-280/paulo-custodio/python/ch-2.py b/challenge-280/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..641cc9ec63
--- /dev/null
+++ b/challenge-280/paulo-custodio/python/ch-2.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+# Challenge 280
+#
+# Task 2: Count Asterisks
+# Submitted by: Mohammad Sajid Anwar
+# You are given a string, $str, where every two consecutive vertical bars are
+# grouped into a pair.
+#
+# Write a script to return the number of asterisks, *, excluding any between
+# each pair of vertical bars.
+#
+# Example 1
+# Input: $str = "p|*e*rl|w**e|*ekly|"
+# Ouput: 2
+#
+# The characters we are looking here are "p" and "w**e".
+# Example 2
+# Input: $str = "perl"
+# Ouput: 0
+# Example 3
+# Input: $str = "th|ewe|e**|k|l***ych|alleng|e"
+# Ouput: 5
+#
+# The characters we are looking here are "th", "e**", "l***ych" and "e".
+
+import sys
+import re
+
+str_input = sys.argv[1] if len(sys.argv) > 1 else ""
+str_input = re.sub(r'\|[^|]*\|', '', str_input)
+count = str_input.count('*')
+print(count)