Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Golden Pyramid by Kurush
from collections import deque
def count_gold(pyramid):
global_max_gold = 0
max_gold = 0
height_index = 0
width_index = 0
search_queue = deque()
search_queue.append([max_gold, height_index, width_index]);
while True:
if not search_queue: break
max_gold, height_index, width_index = search_queue.popleft()
max_gold += pyramid[height_index][width_index]
if height_index + 1 < len(pyramid):
search_queue.append([max_gold, height_index + 1, width_index])
search_queue.append([max_gold, height_index + 1, width_index + 1])
else:
if max_gold > global_max_gold:
global_max_gold = max_gold
return global_max_gold
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert 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"
assert 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"
assert count_gold((
(9,),
(2, 2),
(3, 3, 3),
(4, 4, 4, 4)
)) == 18, "Third example"
June 10, 2014