diff options
author | crupest <crupest@outlook.com> | 2021-09-24 13:41:40 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-09-24 13:41:40 +0800 |
commit | 1d59bac0bbd0a4f5f18cc34157dbaa2d1d256c5c (patch) | |
tree | 2065e3ca128fb3f734960bdaa4b8a0a5b8253d8a /algorithm-experiment/1.1b.cpp | |
parent | 688a7dd4f6321e46d98ff446a547eaa399d584b0 (diff) | |
download | life-1d59bac0bbd0a4f5f18cc34157dbaa2d1d256c5c.tar.gz life-1d59bac0bbd0a4f5f18cc34157dbaa2d1d256c5c.tar.bz2 life-1d59bac0bbd0a4f5f18cc34157dbaa2d1d256c5c.zip |
Add algorithm expriments.
Diffstat (limited to 'algorithm-experiment/1.1b.cpp')
-rw-r--r-- | algorithm-experiment/1.1b.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/algorithm-experiment/1.1b.cpp b/algorithm-experiment/1.1b.cpp new file mode 100644 index 0000000..c64c73e --- /dev/null +++ b/algorithm-experiment/1.1b.cpp @@ -0,0 +1,20 @@ +#include <iostream> + +int main() { + for (int i = 2; i <= 1000; i++) { + std::cout << i << ','; + + int n = i; + + int k = 0; + + while (n != 1) { + n = n % 2 ? n * 3 + 1 : n / 2; + k++; + } + + std::cout << k << '\n'; + } + + return 0; +}
\ No newline at end of file |