From 098c34d31898bb4c3ae81b018eb462c64bc827ca Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Sun, 11 May 2025 15:04:52 -0400 Subject: Challenge 320 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 minimal blog post --- challenge-320/packy-anderson/python/ch-1.py | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 challenge-320/packy-anderson/python/ch-1.py (limited to 'challenge-320/packy-anderson/python/ch-1.py') diff --git a/challenge-320/packy-anderson/python/ch-1.py b/challenge-320/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..8e103a1509 --- /dev/null +++ b/challenge-320/packy-anderson/python/ch-1.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +def maxCount(ints): + pos = 0 + neg = 0 + for int in ints: + if int > 0: + pos += 1 + elif int < 0: + neg +=1 + max_count = max(pos, neg) + explain = ( + f"There are {pos} positive integers.\n" + + f"There are {neg} negative integers.\n" + + f"The maximum between {pos} and {neg} is {max_count}." + ) + return max_count, explain + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(ints): + print(f'Input: @ints = ({comma_join(ints)})') + max_count, explain = maxCount(ints) + print(f'Output: {max_count}\n\n{explain}') + +print('Example 1:') +solution([-3, -2, -1, 1, 2, 3]) + +print('\nExample 2:') +solution([-2, -1, 0, 0, 1]) + +print('\nExample 3:') +solution([1, 2, 3, 4]) -- cgit