+ 30
[M💙 Challenge] Pyramidal Number Stacking 🔺🔢
Monday Blue 💙 Challenge Series #8 Let's try to build a number triangle this week! This challenge was inspired by Pascal's triangle but we will work from bottom-to-top instead of top-to-bottom this time. 💼 TASK Write a program to accept a list of unit digits and stack it in a triangular form. Each successive layer on top was derived from the sum of two adjacent numbers from the lower level. 🔧 EXAMPLE [ 1, 2 ] ➡ 3 1 2 [ 1, 2, 3 ] ➡ 8 3 5 1 2 3 [ 0, 1, 0, 1 ] ➡ 4 2 2 1 1 1 0 1 0 1 ➕ EXTRA Determine the final number on the apex without building the triangle. ❤ BONUS Creative and clear-cut approach is encouraged. Happy Coding!!! 😁💻
32 Réponses
+ 4
Here's my try.
Only the apex number:
https://code.sololearn.com/W45IpdqYeDc1/?ref=app
Added: The Triangle .
Can handle big numbers.
https://code.sololearn.com/WTGjUURQF2Yi/?ref=app
+ 18
Thanks everyone for your participation! We got a few optimized and beautifully presented submissions this week.
I decided to pick a HTML solution by Jonathan for better illustration and I really appreciate for non-web submissions as the padding need to be considered carefully for long numbers and fast calculation of apex number as well.
In fact, you all had done a good job so please don't feel bad if your solution didn't get picked as we still got more to come!
I hope you all enjoy and let's move on to the next challenge! ❤
https://www.sololearn.com/Discuss/853905/?ref=app
+ 16
My try -
https://code.sololearn.com/cFXFGQxF8d5L/?ref=app
Accepts inputs seperated by comma.
By the way, I need to say that this is a very nice challenge.
+ 15
My try
Doesn't get messy with double digits
https://code.sololearn.com/cvVB8y7hGKEn/?ref=app
+ 13
@Pegasus Yup, that's why I suggesting using unit digit as the base. Anyway some extra padding will fix the issue. 😉
+ 10
Creates a centered symmetrical pyramid
https://code.sololearn.com/cDKdgkmA6TzF/?ref=app
+ 7
Another awesome challenge
+ 7
Numbers get messy as they get bigger though
+ 7
here's my [late] try...🐍
the apex is evaluated before the pyramid..
https://code.sololearn.com/cdhg54019JNx/?ref=app
+ 6
herez ittt....
https://code.sololearn.com/cR3Omk05cqW4/?ref=app
+ 6
okk...second version
Functional One Liner.....
(( reveals the top number of the stack ))
https://code.sololearn.com/c93tcwVxK6eZ/?ref=app
+ 6
https://code.sololearn.com/c94kBZ3r85k8/?ref=app
+ 5
okay so it's not a tree but I'm just excited I got recursion to work...
https://code.sololearn.com/c5PBi74ud6vn/?ref=app
+ 5
To learn and to code for these type of challenges and to show your skills.
+ 4
Here's My try in RUBY...
Accepts input and gives output for that.
(input without commas Ex: 0101)
2nd challenge
Thanks for the challenge
https://code.sololearn.com/csMZAocdmLa7/?ref=app
+ 4
Could i turn the input into a list of integers in a more efficient way?
https://code.sololearn.com/cVt09yOidlqA/#py
+ 4
My solution:
https://code.sololearn.com/cTt1Gt6IuJFS/?ref=app
+ 3
Top only without triangle
https://code.sololearn.com/cn6AjPrl5Hx8/?ref=app
+ 3
Here is a C++ example. Is there a faster way in C++?
https://code.sololearn.com/cltH3S0rdpZU/?ref=app