Skip to content

Instantly share code, notes, and snippets.

@Dobiasd
Created June 23, 2016 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dobiasd/17f5eeab2ba0ee6631394f149fc61ce2 to your computer and use it in GitHub Desktop.
Save Dobiasd/17f5eeab2ba0ee6631394f149fc61ce2 to your computer and use it in GitHub Desktop.
std::list<int> collatz_seq(int x)
{
std::list<int> result;
while (x > 1)
{
result.push_back(x);
if (x % 2 == 0)
x = x / 2;
else
x = 3 * x + 1;
}
result.push_back(x);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment