7 kyu

[Code Golf] Number Pyramid Series 1 - Sum of Corners

Description:

Number Pyramid

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

For example, when the pyramid has 3 levels:

  1
 2 3
4 5 6

And the sum of three corners are:

1 + 4 + 6 = 11

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 three corners of the pyramid.

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

  • When there is only one level, return 1 as it is the only corner.

Examples:

sum_corners(0) --> 0
sum_corners(1) --> 1
sum_corners(2) --> 6
sum_corners(3) --> 11

Golfing Message:

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


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

Mathematics
Restricted

Stats:

CreatedJul 5, 2022
PublishedJul 6, 2022
Warriors Trained667
Total Skips11
Total Code Submissions1642
Total Times Completed242
Python Completions242
Total Stars12
% of votes with a positive feedback rating87% of 84
Total "Very Satisfied" Votes67
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes5
Total Rank Assessments26
Average Assessed Rank
7 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • LanXnHn Avatar
  • lechevalier Avatar
Ad