diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-04-13 09:58:10 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-04-13 09:58:10 -0400 |
commit | b067c4eea4e6a12c1157321f65d08a1595690d8e (patch) | |
tree | 56ae3f784821d9109fb6cbefcdf6c3fe14a9e141 /minic | |
parent | 95f1a20e0e9569a892ca4dec6573241dc643a1d2 (diff) | |
download | roux-b067c4eea4e6a12c1157321f65d08a1595690d8e.tar.gz |
add new minic test
Diffstat (limited to 'minic')
-rw-r--r-- | minic/test/collatz.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/minic/test/collatz.c b/minic/test/collatz.c new file mode 100644 index 0000000..1d8a96c --- /dev/null +++ b/minic/test/collatz.c @@ -0,0 +1,33 @@ +void *malloc(); + +main() +{ + int n; + int nv; + int c; + int cmax; + int *mem; + + mem = malloc(sizeof(int) * 4000); + + cmax = 0; + for (nv = 1; nv < 1000; nv++) { + n = nv; + c = 0; + while (n != 1) { + if (n < nv) { + c = c + mem[n]; + break; + } + if (n & 1) + n = 3*n + 1; + else + n = n / 2; + c++; + } + mem[nv] = c; + if (c > cmax) + cmax = c; + } + printf("should print 178: %d\n", cmax); +} |