From b067c4eea4e6a12c1157321f65d08a1595690d8e Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Wed, 13 Apr 2016 09:58:10 -0400 Subject: add new minic test --- minic/test/collatz.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 minic/test/collatz.c (limited to 'minic') 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); +} -- cgit 1.4.1