aboutsummaryrefslogtreecommitdiffstats
path: root/collatz.c
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2020-02-09 15:16:26 -0500
committermjfernez <mjfernez@gmail.com>2020-02-09 15:16:26 -0500
commit93ea7fe5957b62f18e8fbd17a21696bd7de6332d (patch)
treed90aed60d687bcf195f1150777f37cbe8a149814 /collatz.c
parent125ec5bc3d8bfc224b7d32bcfbbc37b9fb5d441f (diff)
downloadProject_Euler_Solutions-93ea7fe5957b62f18e8fbd17a21696bd7de6332d.tar.gz
Organized everything, update README
Diffstat (limited to 'collatz.c')
-rw-r--r--collatz.c31
1 files changed, 0 insertions, 31 deletions
diff --git a/collatz.c b/collatz.c
deleted file mode 100644
index ec77af6..0000000
--- a/collatz.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-// In C, it's immediately obvious my python solution is inefficient
-
-// For keeping track of the length of sequences
-// c is a temporary counter, s changes when c reaches a new maximum
-long int c = 0;
-long int s = 0;
-long int collatz(long int seed){
- c++;
- if(seed == 1)
- return 0;
- if(seed % 2 == 0)
- seed = seed / 2;
- else
- seed = 3 * seed + 1;
- collatz(seed);
-}
-
-int main(){
- for(long int i = 1; i < pow(10, 6); i++){
- c = 0;
- collatz(i);
- if(c > s){
- s = c;
- }
- }
- printf("The longest sequence has %d numbers \n", s);
- return 0;
-}