Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmPython Program for Triangular Matchstick Number

Python Program for Triangular Matchstick Number

Given a number X which represents the floor of a matchstick pyramid, write a program to print the total number of matchstick required to form a pyramid of matchsticks of x floors.

Examples:

Input : X = 1
Output : 3
Input : X = 2
Output : 9

This is mainly an extension of triangular numbers. For a number X, the matchstick required will be three times of X-th triangular numbers, i.e., (3*X*(X+1))/2




# Python program to find X-th triangular
# matchstick number
  
def numberOfSticks(x):
    return (3 * x * (x + 1)) / 2
      
# main()
print(int(numberOfSticks(7)))


Output:

84

Please refer complete article on Triangular Matchstick Number for more details!

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Last Updated :
14 Mar, 2023
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments