The Levine triangle starts as follows:
Row 0: 2
Row 1: 1 1
Row 2: 1 2
Row 3: 1 1 2
To construct each row, read the previous from the right. Row 0 tells us to put two 1s in row 1. Row 1 tells us to put one 1 and one 2 in row 2. Row 2 tells us to put two 1s and one 2 in row 3. Et cetera.
Write a function that computes the sum of the elements in the nth row of the Levine triangle and reports the sum as a string. Codes that can handle the optional tests will earn ten (10) Chris R. Appreciation Points.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers14
Suggested Problems
-
Join Strings with Multiple Different Delimiters
225 Solvers
-
166 Solvers
-
(Linear) Recurrence Equations - Generalised Fibonacci-like sequences
414 Solvers
-
63 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
2147 Solvers
More from this Author323
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I submitted one solution, and it did return the sum as a string, but complained of insufficient memory. Because of the order of operations, it was creating the n=12 array while evaluating n=11, and that array was apparently too large for Cody. Fixed now, but it is apparently going to be a problem for n=12 and above.
My code choked on n = 12 on my laptop. That was the motivation for the three optional tests, as well as for one of the tags.
Disallowing 'if' seems to disallow 'circshift' also, which I assume was not your intent.
Correct. I changed the test to look for 'if '.