packages feed

funcons-simple-0.1.0.3: tests/Kdiverse/Kdiverse3.smp

// copied from K: tests/diverse/collatz.simple
// Program testing Collatz' conjecture up to a user-provided number.

function collatz(n) {
  var s=0;
  print("Testing Collatz' conjecture for n = ",n," ... ");
  while (n > 1) {
    s = s+1;
    if (n == (n/2)*2) { n = n/2; }
    else { n = 3*n+1; }
  }
  print("Done! It took ",s," steps.\n");
}

function main() {
  print("Testing Collatz' conjecture up to what number? ");
  var m = read();
  for (var i=1; i<=m; ++i) { collatz(i); }
  print("Done.  It appears to hold.\n");
}