From f8eeff1f9b16a0c7913cbcb0112cbf61259d574f Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Thu, 29 May 2025 21:31:12 -0400 Subject: Challenge 323 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 blog post --- challenge-323/packy-anderson/python/ch-1.py | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 challenge-323/packy-anderson/python/ch-1.py (limited to 'challenge-323/packy-anderson/python/ch-1.py') diff --git a/challenge-323/packy-anderson/python/ch-1.py b/challenge-323/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..5cbccba4aa --- /dev/null +++ b/challenge-323/packy-anderson/python/ch-1.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +def incDec(operations): + x = 0 + old_x = 0 + o = '' + explain = [] + for op in operations: + x = x + 1 if "++" in op else x - 1 + o = '+' if "++" in op else '-' + explain.append( + 'Operation "{}" => {:2d} {} 1 => {:2d}'.format( + op, old_x, o, x + ) + ) + old_x = x + return x, "\n".join(explain) + +def solution(operations): + display = '"' + '", "'.join(operations) + '"' + print(f'Input: @operations = ({display})') + output, explain = incDec(operations) + print(f'Output: {output}\n\n{explain}') + + +print('Example 1:') +solution(["--x", "x++", "x++"]) + +print('\nExample 2:') +solution(["x++", "++x", "x++"]) + +print('\nExample 3:') +solution(["x++", "++x", "--x", "x--"]) -- cgit