/* 
 * Description:
 * This assignment asks you to study the properties of the radix point
 * representation of rational numbers. In particular, the radix point
 * representation of every rational number decomposes into three 
 * parts, each of which is a sequence of digits in the chosen base B:
 *
 * (a) the integer part
 * (b) the fractional part, which further decomposes into
 *     (b1) the finite transient 
 *     (b2) the finite period (that repeats infinitely many times)
 *
 * This decomposition always exists and is unique if we choose the 
 * shortest possible finite transient, the shortest possible finite period, 
 * and require the period to be 0 whenever multiple choices exist for 
 * the period. In what follows we assume that the decomposition is always
 * chosen in this way. 
 *
 * Example 1: 
 * Consider the rational number 45679/3700, which expands in base B = 10
 * radix point as           12.34567567567567...
 * 
 * The integer part is      12
 * The finite transient is     34
 * The finite period is          567   (this repeats infinitely many times)
 *
 * Example 2:
 * Consider the rational number 23/1, which expands in base B = 10
 * radix point as           23.00000000000000...
 *
 * The integer part is      23
 * The finite transient is        (the transient is empty) 
 * The finite period is        0  (this repeats infinitely many times)
 *
 * Example 3:
 * Consider the rational number 3/2, which expands in base B = 10
 * radix point as           1.500000000000000...
 *
 * The integer part is      1
 * The finite transient is    5
 * The finite period is        0  (this repeats infinitely many times)
 *
 */

package rationalDecompose:

  /*
   * Task: 
   * Write a function that computes the decomposition of a given
   * nonnegative rational number p/q in a given base b. The decomposition
   * is to be returned in a three-tuple (integer, transient, period),
   * where each component of the tuple is a sequence (Seq)
   * of digits in base b, and each digit has type Int.
   *
   * Examples:
   * decompose(45679,3700,10) must return (Seq(1,2),Seq(3,4),Seq(5,6,7))
   * decompose(49,99,10)      must return (Seq(0),Seq[Int](),Seq(4,9))
   * decompose(3,2,10)        must return (Seq(1),Seq(5),Seq(0))
   * 
   */

  def decompose(p: Int, q: Int, b: Int): (Seq[Int],Seq[Int],Seq[Int]) =
    require(p >= 0 && q > 0 && p < 100000 && q < 100000 && b >= 2 && b <= 100) 
    // you may assume p, q, b meet the above requirements
    // Compute the integer part
    val integerPart = p / q
    var remainder = p % q * b

    // Compute the finite transient
    val transient = collection.mutable.ArrayBuffer.empty[Int]
    while (remainder != 0 && transient.length < 100) {
      transient += remainder / q
      remainder = remainder % q * b
    }

    // Compute the finite period
    val period = collection.mutable.ArrayBuffer.empty[Int]
    val remainders = collection.mutable.Map.empty[Int, Int]
    while (remainder != 0 && !remainders.contains(remainder)) {
      remainders(remainder) = period.length
      period += remainder / q
      remainder = remainder % q * b
    }
    if (remainder != 0) {
      val startIndex = remainders(remainder)
      period.insert(startIndex, -1)
    }

    (Seq(integerPart), transient, period.filter(_ != -1).toSeq)
  end decompose

Error on the second last line: "Found:    (transient : scala.collection.mutable.ArrayBuffer[Int])
Required: Seq[Int]"