string get_function_from_name(string name){
ostringstream oss;
oss << name.size();
string ret = "";
ret += "string get_me(){\n int temp[";
ret += oss.str();
ret += "]={";
int cur = 0;
for (int temp = 0; temp < name.size(); temp++){
ostringstream out("");
out << -(cur - (int)name[temp]);
cur = (int)name[temp];
ret += out.str();
if (temp != name.size() - 1)
ret += ",";
}
ret += "};\n string me = \"\";\n int to = 0;\n for (int c = 0; c < ";
ret += oss.str();
ret += "; c++){\n to +=temp[c];\n me+=(char)to;\n }\n return me;\n}";
return ret;
}
It's a weak little function, and I'm wondering how many different username generating function function generators we can come up with!
std::string bf_difference( int k ){
int j = k < 0 ? -k : k, a;
for( int i = 1; i*i <= j; i++ ) if( j%i == 0 ) a = i;
if( a+j/a+5 >= j ) return std::string( j, k < 0 ? '-' : '+' );
elsereturn">" + bf_difference(a) + "[-<" + std::string( j/a, k < 0 ? '-' : '+' ) + ">]<";
}
std::string get_function_from_name( std::string name ){
std::string result;
char prev = 0;
for(unsigned i = 0; i < name.length(); prev = name[i], i++)
result += bf_difference( name[i]-prev ) + ".";
return result;
}
No one said it had to be C++, right? It greatly lacks sophistication, but at least it tries to use loops.. It appears to me that an algorithm to find the shortest expression would be rather complicated.