summary refs log tree commit diff
path: root/minic/test/collatz.c
blob: 1d8a96c0cd833ff9427b6681c321ca3ae10d7f35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
}