Skip to content

rem [terminology]

Terminology

Usage

  • Use for an arithmetic remainder.
  • It is a conventional and clear abbreviation of remainder.
  • Prefer it over r because r commonly means right pointer or row.
seen = {}
while rem:
    if rem in seen:
        repeat_idx = seen[rem]
        parts.insert(repeat_idx, "(")
        parts.append(")")
        break
    seen[rem] = len(parts)
    rem *= 10
    digit, rem = divmod(rem, b)
    parts.append(str(digit))

See 166. Fraction to Recurring Decimal.