6 kyu

[Code Golf] Number Pyramid Series 2 - Sum of Edges

Description:

NOTE: It is recommended to complete the corner case before working on this edge case.


Number Pyramid:

Image a number pyramid starts with 1, and the numbers increasing by 1.

For example, when the pyramid has 4 levels:

   1
  2 3
 4 5 6
7 8 9 10

And the sum of all numbers of the edges (including corners) are:

1 + 2 + 3 + 4 + 6 + 7 + 8 + 9 + 10 = 50 (5 is not on the edges)

Input:

You will be given a number n, which means how many levels the pyramid has.

0 <= n <= 5000


Output:

You need to return the sum of all numbers on the edges (corners are included) of the pyramid.

  • When there is no level, return 0 as there is no edge.

  • When there is only one level, return 1 as it is the only number on edge/corner.

Examples:

sum_edges(0) --> 0 or 0.0
sum_edges(1) --> 1 or 1.0
sum_edges(2) --> 6 or 6.0
sum_edges(3) --> 21 or 21.0
sum_edges(4) --> 50 or 50.0

Golfing Message:

The length of your code should be less or equal to 50.

It is possible to do it within the length of 46.


If you like this series, welcome to do other kata of it.

Mathematics
Restricted

More By Author:

Check out these other kata created by LanXnHn

Stats:

CreatedJul 7, 2022
PublishedJul 8, 2022
Warriors Trained507
Total Skips39
Total Code Submissions941
Total Times Completed76
Python Completions76
Total Stars9
% of votes with a positive feedback rating98% of 32
Total "Very Satisfied" Votes31
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments18
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • LanXnHn Avatar
  • saudiGuy Avatar
Ad