From 0af5f73f09593ee4c911f1eb8ff0733019ddb826 Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Sat, 24 May 2025 14:29:33 -0400 Subject: Challenge 322 solutions by Packy Anderson * Raku that maybe looks like Raku, but mostly like Perl * Perl * Python that definitely looks like Perl * Elixir that looks kinda like Elixir 1 blog post --- challenge-322/packy-anderson/python/ch-1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 challenge-322/packy-anderson/python/ch-1.py (limited to 'challenge-322/packy-anderson/python/ch-1.py') diff --git a/challenge-322/packy-anderson/python/ch-1.py b/challenge-322/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..a42c02c26a --- /dev/null +++ b/challenge-322/packy-anderson/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +def strFormat(strVar, i): + strVar = strVar.replace("-", "") + output = '' + while (len(strVar) > i): + output = "-" + strVar[-i:] + output + strVar = strVar[0:-i] # Python strings are IMMUTABLE + return strVar + output + +def solution(strVar, i): + print(f'Input: $str = "{strVar}", $i = {i}') + output = strFormat(strVar, i) + print(f'Output: "{output}"') + + +print('Example 1:') +solution("ABC-D-E-F", 3) + +print('\nExample 2:') +solution("A-BC-D-E", 2) + +print('\nExample 3:') +solution("-A-B-CD-E", 4) + +print('\nExample 4:') +solution("-A-B-CD-E", 5) \ No newline at end of file -- cgit