aboutsummaryrefslogtreecommitdiff
path: root/challenge-272/luca-ferrari/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-272/luca-ferrari/python/ch-2.py')
-rw-r--r--challenge-272/luca-ferrari/python/ch-2.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-272/luca-ferrari/python/ch-2.py b/challenge-272/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..0a8a0001f4
--- /dev/null
+++ b/challenge-272/luca-ferrari/python/ch-2.py
@@ -0,0 +1,34 @@
+#!python
+
+#
+# Perl Weekly Challenge 272
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-272>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ score = 0
+ string = args[ 0 ]
+ previous = None
+
+ for x in string:
+ if previous is not None:
+ diff = ord( x ) - ord( previous )
+ if diff < 0:
+ diff *= -1
+
+ score += diff
+
+ previous = x
+
+ return score
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )