From 9df1740d3165b92d26f3e39a019cbabd6141d672 Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Tue, 7 May 2024 01:26:42 -0400 Subject: Challenge 268 solutions by Packy Anderson * Raku that maybe looks like Raku * Perl * Python that definitely looks like Perl 1 Blog post --- challenge-268/packy-anderson/python/ch-2.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 challenge-268/packy-anderson/python/ch-2.py (limited to 'challenge-268/packy-anderson/python/ch-2.py') diff --git a/challenge-268/packy-anderson/python/ch-2.py b/challenge-268/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..51acaf6615 --- /dev/null +++ b/challenge-268/packy-anderson/python/ch-2.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +def numberGame(ints): + intSorted = sorted(ints) + new = [] + while intSorted: + x = intSorted.pop(0) + y = intSorted.pop(0) + if x > y: + new.extend([x, y]) + else: + new.extend([y, x]) + return new + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(ints): + print(f'Input: @ints = ({comma_join(ints)})') + new = numberGame(ints) + print(f'Output: ({comma_join(new)})') + +print('Example 1:') +solution([2, 5, 3, 4]) + +print('\nExample 2:') +solution([9, 4, 1, 3, 6, 4, 6, 1]) + +print('\nExample 3:') +solution([1, 2, 2, 3]) \ No newline at end of file -- cgit