//Combo-maker by joeyjojo.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
//Globals are nice
std::ofstream file;
//I stole the following from http://notfaq.wordpress.com/2006/08/30/c-convert-int-to-string/
template <class T>
inline std::string to_string (const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}
//End of stolen goods
//Recursive function
void combos(std::string first, std::string second)
{
size_t secondsize=second.size();
switch (secondsize)
{
// If you want combinations of 6 from a set of 8, the
// number below should be 2 (i.e. 8 minus 6)
case 2:
file << first << std::endl;
break;
default:
for(int i=0; i<secondsize; ++i)
{
std::string newfirst=first, newsecond="";
newfirst += second[i];
for(int j=0; j<secondsize; ++j)
{
if(i != j) newsecond += second[j];
}
//This while removes duplicates (only if they appear together in the string)
while(newfirst[newfirst.size()-1] == second[i+1])
{
i++;
}
combos(newfirst, newsecond);
}
}
}
int main(int argc, char* argv[])
{
if(argc!=2)
{
std::cout << "Give me some work!" << std::endl;
//call it with an argument e.g. "./a.out 01234567"
}else{
file.open("output.txt");
std::string str = to_string(argv[1]);
combos("",str);
//std::string rar="";
//std::cout << rar.at(rar.size()) << std::endl;
}
return 0;
}