aboutsummaryrefslogtreecommitdiff
path: root/challenge-091/paulo-custodio/python/ch-1.py
blob: 7fda504093cb36db65dd2d69b90a763800613335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python

# 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])))