Last active
January 14, 2019 16:40
-
-
Save lunasorcery/0fecc8fea3cc04def030cba753e3c2c9 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
#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