A pyramid of size n is formed as follows: First, the base of the pyramid consists of n numbers, given as a list: [x_1, x_2, ., x_n] The next layer contains n-1 numbers, obtained from adding each pair...


A pyramid of size n is formed as follows:<br>First, the base of the pyramid consists of n numbers, given as a list: [x_1, x_2, ., x_n]<br>The next layer contains n-1 numbers, obtained from adding each pair of adjacent numbers in the lower layer: [x_1 + x_2, x_2 + x_3,<br>x_(n-1) + x_n]<br>The next layer contains n-2 numbers, obtained from adding each pair of adjacent numbers in the lower layer: [x_1 + 2x_2 + x_3, x_2 + 2x_3 + x_4, , x_(n-2) + 2x (n-1) + x_n]<br>This process is repeated until the top layer which has only 1 number.<br>Create a function that takes in a list of numbers in the bottom layer and returns the only number at the top layer. For example, we can form a pyramid having a base of [2, 0, 2, 1]:<br>9<br>4<br>5<br>2<br>3<br>2<br>1<br>>>> pyramid ( [1, 2])<br>3<br>>>> pyramid ([3, 2, 1])<br>8<br>>>> pyramid ([2, e, 2, 1])<br>Write the function pyramid (base) to return the number<br>the top of a pyramid with a given base.<br>

Extracted text: A pyramid of size n is formed as follows: First, the base of the pyramid consists of n numbers, given as a list: [x_1, x_2, ., x_n] The next layer contains n-1 numbers, obtained from adding each pair of adjacent numbers in the lower layer: [x_1 + x_2, x_2 + x_3, x_(n-1) + x_n] The next layer contains n-2 numbers, obtained from adding each pair of adjacent numbers in the lower layer: [x_1 + 2x_2 + x_3, x_2 + 2x_3 + x_4, , x_(n-2) + 2x (n-1) + x_n] This process is repeated until the top layer which has only 1 number. Create a function that takes in a list of numbers in the bottom layer and returns the only number at the top layer. For example, we can form a pyramid having a base of [2, 0, 2, 1]: 9 4 5 2 3 2 1 >>> pyramid ( [1, 2]) 3 >>> pyramid ([3, 2, 1]) 8 >>> pyramid ([2, e, 2, 1]) Write the function pyramid (base) to return the number the top of a pyramid with a given base.

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here