+ 33

[M💙 Challenge] Number Squeezer 🤜🔢🤛

Monday Blue 💙 Challenge Series #12 Let's have some exercises this week! This time we will squeeze a number list from both directions until we get a single integer sum. 💼 TASK Write a program to accept a number list and display the output for each iteration of the squeezing operation with following conditions:- ✔️ The outermost integers from left and right will be squeezed and sum together after each iteration ✔️ When the number list have less than 4 elements, the next iteration will produce a single sum and the process stops. 🔧 TEST CASE [ 1 ] ➡ 1 [ 1, 2 ] ➡ 3 [ 1, 2, 3 ] ➡ 6 [ 1, 2, 3, 4] ➡ 3, 7 10 [ 1, 2, 3, 4, 5 ] ➡ 3, 3, 9 15 [ 1, 2, 3, 4, 5, 6 ] ➡ 3, 3, 4, 11 6, 15 21 [ 1, 2, 3, 4, 5, 6, 7 ] ➡ 3, 3, 4, 5, 13 6, 4, 18 28 ➕ EXTRA Accept an additional integer which determines the squeeze factor that indicate the numbers to be compressed for each iteration. The examples shown above have a squeeze factor of 2. Besides, it's easy to observe that the iteration will stop if the number list consists of less than {2 × squeeze factor} numbers. ❤ BONUS Clear-cut and optimized approach is encouraged. 👍 SPECIAL MENTION (Visualization) https://code.sololearn.com/W4VaTH2ARO4J/?ref=app Happy Coding!!! 😁💻

11th Dec 2017, 1:05 AM
Zephyr Koo
Zephyr Koo - avatar
63 Respostas
+ 12
https://code.sololearn.com/ckmbgvu6K1zY/?ref=app Surely the smallest and most comprehensive solution using recursion :D
5th Dec 2017, 3:46 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 19
Nice challenge. I will make. Edit : I have made ⬇
4th Dec 2017, 2:56 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 19
My try https://code.sololearn.com/c7noYu1xzj2z/?ref=app (yesss!!! I finally posted at the right time !!!)
4th Dec 2017, 4:29 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 17
My code require two inputs, the first is the list of numbers, which are to be separated with comma, example : 1,23,4,5,11,3 and the second input, is the factor(as demanded by Zephyr. https://code.sololearn.com/cO93zx7giz7Q/?ref=app
4th Dec 2017, 4:44 PM
Justine Ogaraku
Justine Ogaraku - avatar
4th Dec 2017, 5:04 PM
LukArToDo
LukArToDo - avatar
+ 15
Challenge accepted 😂
4th Dec 2017, 3:00 PM
Justine Ogaraku
Justine Ogaraku - avatar
4th Dec 2017, 4:46 PM
David Akhihiero
David Akhihiero - avatar
+ 15
@Kinshuk Ok thanks for telling.
4th Dec 2017, 4:49 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 14
By the way, @Zephyr How do you post questions with more than 512 characters? 😀😅😲
4th Dec 2017, 4:42 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
5th Dec 2017, 5:10 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 14
@Aayush I'm not as smart as you think but I believe the people here who submitted the solution are the smart one. Take your time and treat it as an exercise to flex your brain muscle. You'll become a better problem solver along the thinking process! 😉
5th Dec 2017, 3:31 PM
Zephyr Koo
Zephyr Koo - avatar
+ 13
Thanks everyone for your interest and help to clarify the problem. 😄 Yes a squeeze factor of 1 will cause an infinite loop in this case as we will never get a single sum. Python seems to be the most preferable choice for this challenge and perfect when combined with recursion! 😄
5th Dec 2017, 12:30 AM
Zephyr Koo
Zephyr Koo - avatar
+ 12
@Kinshuk I think the squeeze factor must be greater than 1 or else it will be an infinite loop.
4th Dec 2017, 4:48 PM
qwerty
qwerty - avatar
6th Dec 2017, 6:15 AM
Aayush Bhansali
Aayush Bhansali - avatar
+ 12
@Yash Thatte It will be available in 20 mins, stay tuned! 😉
11th Dec 2017, 3:36 AM
Zephyr Koo
Zephyr Koo - avatar
+ 12
Thanks everyone for your participation! I had an emotional roller coaster this week due to the overwhelming response from COTD and fortunately I'm able to spare my time to review the submissions. We got a few interesting submissions this time with elegant recursion and even an animated visualization via HTML too by Jonathan! (This was featured @ SPECIAL MENTION on top) I hope you all enjoy and let's move on to the next challenge! ❤ https://www.sololearn.com/Discuss/919416/?ref=app
11th Dec 2017, 4:31 AM
Zephyr Koo
Zephyr Koo - avatar
+ 11
Your Monday Blue Challenges Require Me to Sit Down And Think ... I am still working on the bouncing ball physics ... You're smart 👍
5th Dec 2017, 3:56 AM
Aayush Bhansali
Aayush Bhansali - avatar
+ 11
@Kinshuk.. you are right
5th Dec 2017, 5:21 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 11
Me knowing Java requires a 50-100 line code whereas Python programmers sum up everything in 10-20 lines
5th Dec 2017, 5:23 AM
Aayush Bhansali
Aayush Bhansali - avatar