Coding Challenge :: Partitions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Coding Challenge :: Partitions

Another one !!! Well, although some of you may already know it, partitions are the ways in which a number can be represented by the sum of other numbers. For example, Partitons of 5 :- 5 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1 Task :- Enter a number and show its partitons. Enjoy coding 😎😎😎 #daring #challenging #forPros

29th Jul 2017, 4:08 PM
Danish Javed
Danish Javed - avatar
8 Answers
+ 10
31st Jul 2017, 9:54 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 3
@Stephen Try to come up with a solution so as to avoid "Time limit exceeds" for values greater than 30 ,suppose. Otherwise, great job!!
29th Jul 2017, 7:06 PM
Danish Javed
Danish Javed - avatar
+ 3
@Danish Javed i know :S thats why its name broken partition
30th Jul 2017, 2:34 PM
Emrullah şahin
Emrullah şahin - avatar
+ 2
Here's a solution. It works, although the sorting of the output could be improved. https://code.sololearn.com/cq4aPK0x07EU/?ref=app
29th Jul 2017, 6:55 PM
Stephen
+ 2
it prints something just like this Partitons of 5 :- 5 3 + 2 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1 https://code.sololearn.com/c4J6cI8oEBYl/?ref=app
30th Jul 2017, 1:19 PM
Emrullah şahin
Emrullah şahin - avatar
+ 1
@Emrullah sahin All partitions are not being printed. Nice try
30th Jul 2017, 2:26 PM
Danish Javed
Danish Javed - avatar
5th Aug 2017, 4:01 AM
Hepson
Hepson - avatar
0
my try in c++ #include <iostream> using namespace std; int main() { int n,i,j; cout<<"enter the number"; cin>>n; cout<<"\n"; i=n; while(i>=1) { cout<<i; j=0; while(j<(n-i)) { cout<<"+1"; j++; } cout<<"\n"; i--; } return 0; }
6th Aug 2017, 5:57 AM
Arnold
Arnold - avatar