Algebraic Pyramid Challenge

algebraic-pyramidFor the purpose of this challenge we will use algebraic pyramids pointing downwards (or upside down pyramids!).

The idea of this mathematical puzzle is to fill in all the bricks of a pyramid based on the following rule:

  • To work out the value of a brick, add the values of the two adjacent bricks above it.

algebraic-pyramid-rule

Python Challenge #1: Fix sized pyramids


This Python challenge will consist of writing a procedure that will take a list of values as a parameter, and will as a result generate and output an upside down pyramid where the top layer of the pyramid will contain all the values from the given list.

To simplify this problem, we will first assume that the list of number will always contains exactly 4 values.
For example:
algebraic-pyramid-list

The output of our procedure should be as follows:
algebraic-pyramid

Challenge #1: Python Code:


You will need to complete the following python code to work out and print all the layers of the pyramid.

Challenge #1: Test Plan


Check that your code is working using the following list of 4 values.

Test # List Expected Output Pass/Fail?
#1 [4,6,8,2] algebraic-pyramid-test-2
#2 [30,12,10,5] algebraic-pyramid-test-1
#3 [3,6,9,12] algebraic-pyramid-test-3

Challenge #2: Using lists of different sizes


The second challenge consists of adapting the code from challenge 1 to make sure that it works for any list (of any length) of values.

Challenge #2: Test Plan

Test # List Expected Output Pass/Fail?
#1 [3,6,9] algebraic-pyramid-test-3-layers
#2 [30,12,10,5] algebraic-pyramid-test-1
#3 [1,2,3,4,5,6] algebraic-pyramid-test-6-layers

Did you like this challenge?

Click on a star to rate it!

Average rating 4.2 / 5. Vote count: 13

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: