diff options
Diffstat (limited to 'challenge-091/paulo-custodio/python')
| -rw-r--r-- | challenge-091/paulo-custodio/python/ch-1.py | 25 | ||||
| -rw-r--r-- | challenge-091/paulo-custodio/python/ch-2.py | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-091/paulo-custodio/python/ch-1.py b/challenge-091/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..3eeb00c151 --- /dev/null +++ b/challenge-091/paulo-custodio/python/ch-1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +# THE WEEKLY CHALLENGE - 091 +# TASK #1: Count Number +# +# You are given a positive number $N. Write a script to count number and +# display as you read it. + +# Solution with regular expressions: +# Just match the first digit and a sequence of equal matches, capture the +# results and show them. + +import re +import sys + +def count_number(n): + n = str(n) + out = '' + while n != '': + m = re.match(r'^((\d)\2*)', n) + out += str(m.end())+m.group(2) + n = n[m.end():] + return out + +print(count_number(int(sys.argv[1]))) diff --git a/challenge-091/paulo-custodio/python/ch-2.py b/challenge-091/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..84db6f66d8 --- /dev/null +++ b/challenge-091/paulo-custodio/python/ch-2.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +# THE WEEKLY CHALLENGE - 091 +# TASK #2: Jump Game +# +# You are given an array of positive numbers @N, where value at each index +# determines how far you are allowed to jump further. Write a script to decide +# if you can jump to the last index. Print 1 if you are able to reach the last +# index otherwise 0. + +import sys + +n = [int(x) for x in sys.argv[1:]] +pos = 0 +while pos < len(n)-1 and n[pos] != 0: + pos += n[pos] +if pos==len(n)-1: + print(1) +else: + print(0) |
