Created
January 5, 2010 20:40
-
-
Save metaxy/269696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtCore/QCoreApplication> | |
#include <math.h> | |
#include <QtDebug> | |
static QList<QList<qint16> >currentList; | |
void findMore(QList<qint16> l) | |
{ | |
for(int i = 0;i < l.size();i++) { | |
int c = l.at(i); | |
if(c > 1) { | |
QList<qint16> n = l; | |
n.removeAt(i); | |
n.append(c/2); | |
n.append(c/2); | |
// qDebug() << "findMore = " << c << l << n; | |
int count = 0; | |
for(int j=0; j < n.size();j++) { | |
if(n.at(j) == 1) | |
count++; | |
} | |
if(count <= 3) { | |
currentList << n; | |
findMore(n); | |
} | |
} | |
} | |
} | |
qint16 my(qint16 number) | |
{ | |
qint16 start = sqrt(number); | |
int c = number; | |
QList<qint16> l; | |
for(qint16 i = start + 1; i >= 0;i--) { | |
qint16 currentPow = pow(2,i); | |
qint16 res = c - currentPow; | |
if(res >= 0) { | |
c = res; | |
l << currentPow; | |
qDebug() << currentPow; | |
} | |
} | |
currentList << l; | |
findMore(l); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
my(-5); | |
//remove all invalid | |
qDebug() << "blätter = " << currentList.size(); | |
static QList<QList<qint16> > newList; | |
for(int i= 0;i < currentList.size();i++) { | |
qint16 max = 1; | |
QList<qint16> l = currentList.at(i); | |
for(int j = 0; j < l.size(); j++) { | |
if(l.at(j) > max) | |
max = l.at(j); | |
} | |
bool bad = false; | |
for(int j = max; max > 0; max/=2) { | |
qint16 count = 0; | |
for(int y = 0;y < l.size();y++) { | |
if(l.at(y) == max) | |
count++; | |
} | |
if(count > 3) { | |
bad = true;; | |
break; | |
} | |
} | |
if(bad == false) { | |
newList << l; | |
} | |
} | |
currentList = newList; | |
//sort all | |
for(int i =0; i < currentList.size();i++) { | |
QList<qint16> l = currentList.at(i); | |
bool ver = false; | |
do { | |
ver = false; | |
for(int j = 0; j < l.size() -1;j++) { | |
if(l.at(j) < l.at(j+1)) { | |
l.swap(j,j+1); | |
ver = true; | |
} | |
} | |
} while(ver); | |
currentList.replace(i,l); | |
} | |
//remove equal | |
newList = currentList; | |
QList<qint16> badList; | |
for(int i =0; i < currentList.size();i++) { | |
QList<qint16> l = currentList.at(i); | |
for(int j = 0; j < currentList.size();j++) { | |
if(j != i && !badList.contains(j) && !badList.contains(i) && currentList.at(i) == currentList.at(j)) { | |
badList << j; | |
} | |
} | |
} | |
bool ver = false; | |
do { | |
ver = false; | |
for(int j = 0; j < badList.size() -1;j++) { | |
if(badList.at(j) < badList.at(j+1)) { | |
badList.swap(j,j+1); | |
ver = true; | |
} | |
} | |
} while(ver); | |
for(int i = 0; i < badList.size();i++) { | |
currentList.removeAt(badList.at(i)); | |
} | |
qDebug() << "endList = " << currentList <<" size = " <<currentList.size(); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment