From eaad15f95557cf797ea0d02fad9eb7120eb63e2c Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Wed, 28 Feb 2024 00:55:49 -0500 Subject: Challenge 258 solutions by Packy Anderson * Raku * Perl * Python 1 Blog post --- challenge-258/packy-anderson/python/ch-1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 challenge-258/packy-anderson/python/ch-1.py (limited to 'challenge-258/packy-anderson/python/ch-1.py') diff --git a/challenge-258/packy-anderson/python/ch-1.py b/challenge-258/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..fb5188ace1 --- /dev/null +++ b/challenge-258/packy-anderson/python/ch-1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +from math import floor, log10 + +def evenDigitCount(ints): + count = 0; # in case there are no even digit ints + for n in ints: + if floor(log10(n) + 1) % 2 == 0: count += 1 + return count + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(ints): + print(f'Input: @arr = ({comma_join(ints)})') + print(f'Output: {evenDigitCount(ints)}') + +print('Example 1:') +solution([10, 1, 111, 24, 1000]) + +print('\nExample 2:') +solution([111, 1, 11111]) + +print('\nExample 3:') +solution([2, 8, 1024, 256]) -- cgit