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 | 01cf50d0c0bce56a1c2599e6ab77033ce9595450 (patch) | |
tree | d527b8891f18421d24edf2b827a4a392858ef4fc /works/life/algorithm-experiment/1.1b.cpp | |
parent | 9bf99897b7122d5f6269386be4fe0a215b95313b (diff) | |
download | crupest-01cf50d0c0bce56a1c2599e6ab77033ce9595450.tar.gz crupest-01cf50d0c0bce56a1c2599e6ab77033ce9595450.tar.bz2 crupest-01cf50d0c0bce56a1c2599e6ab77033ce9595450.zip |
import(life): Add algorithm expriments.
Diffstat (limited to 'works/life/algorithm-experiment/1.1b.cpp')
-rw-r--r-- | works/life/algorithm-experiment/1.1b.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/works/life/algorithm-experiment/1.1b.cpp b/works/life/algorithm-experiment/1.1b.cpp new file mode 100644 index 0000000..c64c73e --- /dev/null +++ b/works/life/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 |