aboutsummaryrefslogtreecommitdiff
path: root/challenge-152/abigail/python/ch-1.py
blob: c9062f30708eae332551d114c5a5ce693464c391 (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/local/bin/python3

#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-152
#

#
# Run as: python ch-1.py < input-file
#

import fileinput

for line in fileinput . input ():
    minsum = 0
    n      = 1
    m      = n
    min    = 0
    for num in line . strip () . split (" "):
        num = int (num)
        if n == m or num < min:
            min = num
        m = m - 1
        if m == 0:
            n      = n + 1
            m      = n
            minsum = minsum + min
            min    = 0
    print (minsum)