Skip to content

Instantly share code, notes, and snippets.

@lunasorcery
Last active January 14, 2019 16:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunasorcery/0fecc8fea3cc04def030cba753e3c2c9 to your computer and use it in GitHub Desktop.
Save lunasorcery/0fecc8fea3cc04def030cba753e3c2c9 to your computer and use it in GitHub Desktop.
#define SUPPRESS_SUBSCRIPT_WARNING 1
#include <iostream>
#include <string>
#include <random>
const int kMaxDepth = 5;
std::string emptyString(int depth=0, bool singular=false)
{
++depth;
if (depth > kMaxDepth)
{
return "\"\"";
}
bool indirect = rand() & 1;
if (indirect)
{
if (singular)
{
return "(&*"+emptyString(depth)+")";
}
else
{
return "&*"+emptyString(depth);
}
}
std::string s = "\"\"";
while (rand() & 1)
{
s += "\"\"";
}
return s;
}
std::string zero(int depth=0)
{
++depth;
if (depth > kMaxDepth)
{
return "*\"\"";
}
switch (rand() % 6)
{
case 1: return zero(depth) + "&" + zero(depth);
case 2: return zero(depth) + "*" + zero(depth);
case 3: return "*&" + zero(depth);
#if SUPPRESS_SUBSCRIPT_WARNING
case 4: return emptyString(depth, true) + "[+" + zero(depth) + "]";
#else
case 4: return emptyString(depth, true) + "[" + zero(depth) + "]";
#endif
case 5: return "(" + zero(depth) + ")[" + emptyString(depth) + "]";
}
return "*" + emptyString(depth);
}
int main()
{
srand(time(NULL));
std::cout << zero() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment