+ 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!!! 😁💻

6th Nov 2017, 4:02 AM
Zephyr Koo
Zephyr Koo - avatar
32 odpowiedzi
+ 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
6th Nov 2017, 11:07 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 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
13th Nov 2017, 5:28 AM
Zephyr Koo
Zephyr Koo - avatar
+ 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.
6th Nov 2017, 1:00 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 15
My try Doesn't get messy with double digits https://code.sololearn.com/cvVB8y7hGKEn/?ref=app
6th Nov 2017, 9:41 AM
David Akhihiero
David Akhihiero - avatar
+ 13
@Pegasus Yup, that's why I suggesting using unit digit as the base. Anyway some extra padding will fix the issue. 😉
6th Nov 2017, 9:51 AM
Zephyr Koo
Zephyr Koo - avatar
6th Nov 2017, 5:27 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 10
Creates a centered symmetrical pyramid https://code.sololearn.com/cDKdgkmA6TzF/?ref=app
7th Nov 2017, 4:50 PM
David Ashton
David Ashton - avatar
+ 7
Another awesome challenge
6th Nov 2017, 5:20 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
Numbers get messy as they get bigger though
6th Nov 2017, 9:43 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
here's my [late] try...🐍 the apex is evaluated before the pyramid.. https://code.sololearn.com/cdhg54019JNx/?ref=app
6th Nov 2017, 4:49 PM
m abrate
m abrate - avatar
6th Nov 2017, 5:06 AM
sayan chandra
sayan chandra - avatar
+ 6
okk...second version Functional One Liner..... (( reveals the top number of the stack )) https://code.sololearn.com/c93tcwVxK6eZ/?ref=app
6th Nov 2017, 5:21 AM
sayan chandra
sayan chandra - avatar
+ 6
https://code.sololearn.com/c94kBZ3r85k8/?ref=app
9th Nov 2017, 2:02 AM
Marfik Em
Marfik Em - avatar
+ 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
6th Nov 2017, 7:45 AM
Adib Attie
Adib Attie - avatar
+ 5
To learn and to code for these type of challenges and to show your skills.
6th Nov 2017, 12:36 PM
Prasad K G
Prasad K G - avatar
+ 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
6th Nov 2017, 1:00 PM
Prasad K G
Prasad K G - avatar
+ 4
Could i turn the input into a list of integers in a more efficient way? https://code.sololearn.com/cVt09yOidlqA/#py
6th Nov 2017, 9:54 PM
Ben Faus
Ben Faus - avatar
7th Nov 2017, 11:41 AM
Edgeton
Edgeton - avatar
6th Nov 2017, 10:01 PM
Вадим Сухотин (Vadim Sukhotin)
Вадим Сухотин (Vadim Sukhotin) - avatar
+ 3
Here is a C++ example. Is there a faster way in C++? https://code.sololearn.com/cltH3S0rdpZU/?ref=app
7th Nov 2017, 2:07 AM
Bob
Bob - avatar