contextInteger.pl

Jump to: Site Navigation

NAME

contextInteger.pl - adds integer related functions primeFactorization, phi, tau, isPrime, randomPrime, lcm, and gcd.

DESCRIPTION

This is a Parser context that adds integer related functions. This forces students to only enter integers as their answers.

USAGE

        Context("Integer")

  # generates an array of each prime factor
  @a = primeFactorization(1000);
  ANS(List(@a)->cmp);

  # get the gcd
  $b = gcd(5, 2);
  ANS($b->cmp);

  # get lcm
  $c = lcm(36, 90);
  ANS($c->cmp);

  # get phi
  $d = phi(365);
  ANS($d->cmp);
        
  # get tau
  $e = tau(365);
  ANS($e->cmp);

  # check if prime
  $f = isPrime(10); #False
  $h = isPrime(5); #True

  # get a random prime in a range
  $randomPrime = randomPrime(100, 1000);

Site Navigation