aboutsummaryrefslogtreecommitdiff
path: root/challenge-322/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2025-05-25 22:02:38 +1000
committerSimon Green <mail@simon.green>2025-05-25 22:02:38 +1000
commitf8ffba5d2256ee11e2a9ff667cc042b12c4b307e (patch)
treea484ff944e813d369c83b867ad1242e4a6e5d637 /challenge-322/sgreen/python/ch-1.py
parent6c467a026c325f27386294744ad5d0456d6c1c50 (diff)
downloadperlweeklychallenge-club-f8ffba5d2256ee11e2a9ff667cc042b12c4b307e.tar.gz
perlweeklychallenge-club-f8ffba5d2256ee11e2a9ff667cc042b12c4b307e.tar.bz2
perlweeklychallenge-club-f8ffba5d2256ee11e2a9ff667cc042b12c4b307e.zip
sgreen solutions to challenge 322
Diffstat (limited to 'challenge-322/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-322/sgreen/python/ch-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-322/sgreen/python/ch-1.py b/challenge-322/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..7d58247b47
--- /dev/null
+++ b/challenge-322/sgreen/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def string_format(input_string: str, size: int) -> str:
+ # Remove existing dashes
+ input_string = input_string.replace("-", "")
+
+ # The start value is the position of the first characters, so the remaining
+ # characters are a multiple of 'size'
+ start = len(input_string) % size
+ parts = []
+
+
+ if start:
+ # The first group will be smaller than the rest
+ parts.append(input_string[0:start])
+
+ for pos in range(start, len(input_string), size):
+ # Group the remain characters by size.
+ parts.append(input_string[pos:pos+size])
+
+ return '-'.join(parts)
+
+def main():
+ result = string_format(sys.argv[1], int(sys.argv[2]))
+ print(result)
+
+
+if __name__ == '__main__':
+ main()