/* Independent check of Collatz delay records on 1..10^7, written by the verifier.
   Different language and method from the bundle: C with 128-bit trajectory values, no
   memo of earlier delays, each n's trajectory followed all the way to 1, overflow checked. */
#include <stdio.h>
#include <stdint.h>
int main(void) {
  const uint64_t N = 10000000ULL;
  long best = -1; int count = 0; uint64_t last = 0;
  unsigned __int128 peak = 0;
  for (uint64_t n = 1; n <= N; n++) {
    unsigned __int128 x = n; long d = 0;
    while (x != 1) {
      if (x & 1) {
        if (x > (((unsigned __int128)-1) - 1) / 3) { fprintf(stderr, "overflow at %llu\n", (unsigned long long)n); return 1; }
        x = 3 * x + 1;
      } else x >>= 1;
      if (x > peak) peak = x;
      d++;
    }
    if (d > best) { best = d; count++; last = n; printf("%llu,%ld\n", (unsigned long long)n, d); }
  }
  fprintf(stderr, "records=%d last_n=%llu max_delay=%ld peak_value=%llu\n", count, (unsigned long long)last, best, (unsigned long long)peak);
  return 0;
}
