Radix-point decomposition of a rational number
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:

the integer part
the fractional part, which further decomposes into
the finite transient
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…. Here the integer part is 12, the finite transient is 34, and 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…. Here the integer part is 23, the finite transient is empty, and 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…. Here the integer part is 1, the finite transient is 5, and the finite period is 0 (this repeats infinitely many times).

/* 
 * 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
    ???
  end decompose

Make sure your solution passess these tests:
package rationalDecompose

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should._

class rationalDecomposeSpec extends AnyFlatSpec with Matchers:
    "decompose" should "return the period part with the correct length" in {
        val test = Seq(((557, 12345, 10), 822),
        ((34567, 98765, 11), 19752),
        ((34567, 98765,  2), 3292),
        ((  567,   991,  2), 495),
        ((    1, 15017, 10), 15016))

        for ((p, q, b), answer) <- test do
            withClue("For p = %d, q = %d, b = %d, ".format(p, q, b)) {
                decompose(p, q, b)._3.length shouldBe answer
            }
    }

    "decompose" should "produce the correct results" in {
        val test = Seq((( 5, 1, 10), (List(5), List[Int](), List(0))),
        ((98, 10, 10), (List(9), List(8), List(0))),
        ((123, 1, 10), (List(1,2,3), List[Int](), List(0))),
        ((45, 99, 10), (List(0), List[Int](), List(4,5))),
        ((34038, 275, 10), (List(1,2,3), List(7,7), List(4,5))),
        ((18245, 19998, 10), (List(0), List(9), List(1,2,3,4))))

        for ((p, q, b), answer) <- test do
            withClue("For p = %d, q = %d, b = %d, ".format(p, q, b)) {
                decompose(p, q, b) should equal (answer)
            }
    }