static ItIt collatzSequence(long n) { ret collatzSequence(bigInt(n)); } static ItIt collatzSequence(BigInt _n) { ret new ItIt { BigInt three = bigInt(3); BigInt n; public bool hasNext() { ret neq(n, BigInt.ONE); } public BigInt next() { if (n == null) ret n = _n; // first number if (even(n.intValue())) n = div(n, BigInt.TWO); else n = plus(mul(n, three), BigInt.ONE); ret n; } }; }