Skip to content

Instantly share code, notes, and snippets.

@Adspartan
Created February 6, 2019 16:01
Show Gist options
  • Save Adspartan/09403bde7820f116f54715fc9ffc5654 to your computer and use it in GitHub Desktop.
Save Adspartan/09403bde7820f116f54715fc9ffc5654 to your computer and use it in GitHub Desktop.
std::vector<std::string> recursion(std::vector<char> chars, int min_rec, int max_rec)
{
std::vector<std::string> results;
if (min_rec <= 1)
{
for (char c : chars)
{
results.push_back(std::string(1, c));
}
}
if (max_rec == 1)
{
return results;
}
auto rec = recursion(chars, min_rec - 1, max_rec - 1);
for (auto c : chars)
{
for (auto s2 : rec)
{
results.push_back(c + s2);
}
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment