-
Notifications
You must be signed in to change notification settings - Fork 0
/
gold_pyramid.py
41 lines (36 loc) · 892 Bytes
/
gold_pyramid.py
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
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/env python3
def count_gold(pyramid):
s = pyramid[0][0]
pos = 0
for nl, l in enumerate(pyramid[1:]):
pos = pos if l[pos] > l[pos+1] else pos+1
s += l[pos]
return s
def test():
#These "asserts" using only for self-checking and not necessary for auto-testing
print(count_gold((
(1,),
(2, 3),
(3, 3, 1),
(3, 1, 5, 4),
(3, 1, 3, 1, 3),
(2, 2, 2, 2, 2, 2),
(5, 6, 4, 5, 6, 4, 3)
))) #== 23, "First example"
print(count_gold((
(1,),
(2, 1),
(1, 2, 1),
(1, 2, 1, 1),
(1, 2, 1, 1, 1),
(1, 2, 1, 1, 1, 1),
(1, 2, 1, 1, 1, 1, 9)
)))# == 15, "Second example"
print(count_gold((
(9,),
(2, 2),
(3, 3, 3),
(4, 4, 4, 4)
)))# == 18, "Third example"
if __name__ == '__main__':
test()