blaise/vendor/qbe/minic/test/collatz.c
Graeme Geldenhuys 25de8be212 Fix compilation errors; vendor QBE 1.2; end-to-end Hello World works
Fix TProgram.Uses reserved-word clash (renamed to UsedUnits), nested
brace-comment in uParser.pas, and missing uAST in Blaise.pas uses clause.

Vendor QBE 1.2 source in vendor/qbe/ (built locally with make; binary
excluded via .gitignore). End-to-end pipeline confirmed: Blaise compiles
Hello World and Calc (6*7=42) to native x86_64 Linux binaries.

71/71 FPCUnit tests passing.
2026-04-20 16:38:57 +01:00

34 lines
401 B
C

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);
}