+ 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
8 odpowiedzi
+ 10
Looks like I'm late. My try:
https://code.sololearn.com/Wqh87BAOodN5/?ref=app
+ 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!!
+ 3
@Danish Javed i know :S thats why its name broken partition
+ 2
Here's a solution. It works, although the sorting of the output could be improved.
https://code.sololearn.com/cq4aPK0x07EU/?ref=app
+ 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
+ 1
@Emrullah sahin All partitions are not being printed.
Nice try
+ 1
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;
}