aboutsummaryrefslogtreecommitdiff
path: root/challenge-204/sgreen/python/ch-2.py
blob: 0ecfbd91ebf9a7a346fae1bc39565142fe826815 (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 python3

import re
import sys


def main(n):
    # Remove the last two numbers
    c = int(n.pop())
    r = int(n.pop())

    # Check there there is a viable solution
    if len(n) != c * r:
        print('0')
        return

    # Print the result
    for i in range(0, len(n), c):
        print('[ ' + ' '.join(n[i:i+c]) + ' ]')


if __name__ == '__main__':
    # Extract all the integers
    inputs = ' '.join(sys.argv[1:])
    nums = re.findall(r'-?\d+', inputs)
    main(nums)