aboutsummaryrefslogtreecommitdiff
path: root/challenge-336/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2025-08-31 21:45:29 +1000
committerSimon Green <mail@simon.green>2025-08-31 21:45:29 +1000
commitaae335bccca20a06aa5a45e5cafd50cca347cff3 (patch)
treeb6d624e56150a4349f2652abae9a70e1ee889323 /challenge-336/sgreen/python/ch-1.py
parent923952d5af66503e9cd8d065a329f304796eab80 (diff)
downloadperlweeklychallenge-club-aae335bccca20a06aa5a45e5cafd50cca347cff3.tar.gz
perlweeklychallenge-club-aae335bccca20a06aa5a45e5cafd50cca347cff3.tar.bz2
perlweeklychallenge-club-aae335bccca20a06aa5a45e5cafd50cca347cff3.zip
sgreen solutions to challenge 336
Diffstat (limited to 'challenge-336/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-336/sgreen/python/ch-1.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-336/sgreen/python/ch-1.py b/challenge-336/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..d6bd5aa0df
--- /dev/null
+++ b/challenge-336/sgreen/python/ch-1.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+
+import sys
+from collections import Counter
+
+def equal_group(ints: list) -> bool:
+ # Calculate the frequency of each integer in the list
+ freq = Counter(ints).values()
+
+ # If any integer appears only once, it is always false.
+ if min(freq) == 1:
+ return False
+
+ # Check if all frequencies are evenly divisible by an integer.
+ for i in range(2, max(freq) + 1):
+ if all(f % i == 0 for f in freq):
+ return True
+
+ return False
+
+
+def main():
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ result = equal_group(array)
+ print(result)
+
+
+if __name__ == '__main__':
+ main()