aboutsummaryrefslogtreecommitdiff
path: root/challenge-145/sgreen/python/ch-1.py
blob: 7c18890304bb139b21197fc1a3512a9f2d962e63 (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
27
28
#!/usr/bin/env python

import sys
import re


def main(inputs):
    first_nums = list(map(int, re.findall(r'-?\d+', inputs[0])))
    second_nums = list(map(int, re.findall(r'-?\d+', inputs[1])))

    if len(first_nums) != len(second_nums):
        raise ValueError('Arrays are of different lengths')

    dots = []
    sums = []
    for i in range(len(first_nums)):
        dots.append(f'({first_nums[i]} × {second_nums[i]})')
        sums.append(first_nums[i] * second_nums[i])

    print(' + '.join(dots) +
          ' => ' +
          ' + '.join(map(str, sums)) +
          ' => ' +
          str(sum(sums)))


if __name__ == '__main__':
    main(sys.argv[1:])