diff options
Diffstat (limited to 'challenge-333/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-333/packy-anderson/python/ch-2.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-333/packy-anderson/python/ch-2.py b/challenge-333/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..075a48007a --- /dev/null +++ b/challenge-333/packy-anderson/python/ch-2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +def duplicate_zeros(ints): + size = len(ints) + dest = [] + while len(dest) < size: + i = ints.pop(0) + dest.append(i) + if i == 0: dest.append(i) + return dest[0:size] + +def int_join(joiner, arr): + return joiner.join(map(lambda i: str(i), arr)) + +def solution(ints): + print(f'Input: @ints = ({int_join(", ", ints)})') + print(f'Output: ({int_join(", ", duplicate_zeros(ints))})') + +print('Example 1:') +solution([1, 0, 2, 3, 0, 4, 5, 0]) + +print('\nExample 2:') +solution([1, 2, 3]) + +print('\nExample 3:') +solution([1, 2, 3, 0]) + +print('\nExample 4:') +solution([0, 0, 1, 2]) + +print('\nExample 5:') +solution([1, 2, 0, 3, 4]) |
