From b863d69689ab5c27820954f0534d8b47a2c7bd86 Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Fri, 2 Aug 2024 02:31:27 -0400 Subject: Challenge 280 solutions by Packy Anderson * Raku that maybe looks like Raku, but mostly like Perl * Perl * Python that definitely looks like Perl * Elixir 1 Blog post --- challenge-280/packy-anderson/python/ch-1.py | 27 +++++++++++++++++++++++++++ challenge-280/packy-anderson/python/ch-2.py | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 challenge-280/packy-anderson/python/ch-1.py create mode 100755 challenge-280/packy-anderson/python/ch-2.py (limited to 'challenge-280/packy-anderson/python') diff --git a/challenge-280/packy-anderson/python/ch-1.py b/challenge-280/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..def9b93832 --- /dev/null +++ b/challenge-280/packy-anderson/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +from collections import Counter + +def twiceAppearance(str): + count = Counter() + for char in str: + count[char] += 1 + if count[char] > 1: + return char + return "␀" # fallback + +def solution(str): + print(f'Input: $str = "{str}"') + print(f'Output: "{twiceAppearance(str)}"') + +print('Example 1:') +solution("acbddbca") + +print('\nExample 2:') +solution("abccd") + +print('\nExample 3:') +solution("abcdabbb") + +print('\nExample 4:') +solution("abcdefg") diff --git a/challenge-280/packy-anderson/python/ch-2.py b/challenge-280/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..bdbf0cbfc0 --- /dev/null +++ b/challenge-280/packy-anderson/python/ch-2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +from collections import Counter +import re + +def countAsterisks(str): + count = Counter(re.sub(r'\|[^|]+\|', '', str)) + return count["*"] + +def solution(str): + print(f'Input: $str = "{str}"') + print(f'Output: {countAsterisks(str)}') + +print('Example 1:') +solution("p|*e*rl|w**e|*ekly|") + +print('\nExample 2:') +solution("perl") + +print('\nExample 3:') +solution("th|ewe|e**|k|l***ych|alleng|e") -- cgit