aboutsummaryrefslogtreecommitdiff
path: root/works/life/algorithm-experiment/1.1b.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-09-24 13:41:40 +0800
committercrupest <crupest@outlook.com>2021-09-24 13:41:40 +0800
commit01cf50d0c0bce56a1c2599e6ab77033ce9595450 (patch)
treed527b8891f18421d24edf2b827a4a392858ef4fc /works/life/algorithm-experiment/1.1b.cpp
parent9bf99897b7122d5f6269386be4fe0a215b95313b (diff)
downloadcrupest-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.cpp20
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