Skip to content

Instantly share code, notes, and snippets.

@Dobiasd
Created November 26, 2015 10:31
Show Gist options
  • Save Dobiasd/77587769cbc0e13ed582 to your computer and use it in GitHub Desktop.
Save Dobiasd/77587769cbc0e13ed582 to your computer and use it in GitHub Desktop.
std::list<std::uint64_t> collatz_seq(std::uint64_t x)
{
std::list<std::uint64_t> 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