diff options
| author | Packy Anderson <packy@cpan.org> | 2025-05-29 21:31:12 -0400 |
|---|---|---|
| committer | Packy Anderson <packy@cpan.org> | 2025-05-29 21:31:12 -0400 |
| commit | f8eeff1f9b16a0c7913cbcb0112cbf61259d574f (patch) | |
| tree | 23e3c5c280b96b08aeeff97e0059d8f5bd1d5722 /challenge-323/packy-anderson/python/ch-1.py | |
| parent | 6baf6eb311334b1ba4dd3101f7ba1d27120989db (diff) | |
| download | perlweeklychallenge-club-f8eeff1f9b16a0c7913cbcb0112cbf61259d574f.tar.gz perlweeklychallenge-club-f8eeff1f9b16a0c7913cbcb0112cbf61259d574f.tar.bz2 perlweeklychallenge-club-f8eeff1f9b16a0c7913cbcb0112cbf61259d574f.zip | |
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
Diffstat (limited to 'challenge-323/packy-anderson/python/ch-1.py')
| -rwxr-xr-x | challenge-323/packy-anderson/python/ch-1.py | 33 |
1 files changed, 33 insertions, 0 deletions
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--"]) |
