[MšŸ’™ Challenge] Number Squeezer šŸ¤œšŸ”¢šŸ¤› | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
62 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