House of Cards

Published by Caleb Miller in

The image below shows a sequence of larger and larger houses of cards, with the total number of cards included for each:

House of Cards

Given the tower height n, return the number of cards needed to construct a full house of cards.

Examples

cardsNeeded(3) ➞ 15

cardsNeeded(4) ➞ 26

cardsNeeded(0) ➞ 0

Notes

The height should always be equal or greater than 0. Return "invalid" if the value given doesn't abide by this rule.

Watch a quick demo on how Edabit works.