Question: Please solve the following functions using Scala! object arithmetic { def sqrt(n: Int): Option[Int] = { // = None if n 1 } def gcd(n:
Please solve the following functions using Scala!
object arithmetic { def sqrt(n: Int): Option[Int] = { // = None if n 1 } def gcd(n: Int, m: Int): Option[Int] = { // = None if n or m
object testArith extends App { println("gcd(15, 12) = " + arithmetic.gcd(15, 12)) println("lcm(15, 12) = " + arithmetic.lcm(15, 12)) println("gcd(13, 12) = " + arithmetic.gcd(13, 12)) println("gcd(-13, 12) = " + arithmetic.gcd(-13, 12)) println("phi(9)= " + arithmetic.phi(9)) println("sqrt(49) = " + arithmetic.sqrt(49)) println("sqrt(37) = " + arithmetic.sqrt(37)) println("sqrt(35) = " + arithmetic.sqrt(35)) println("log(64) = " + arithmetic.log(64)) println("log(130) = " + arithmetic.log(130)) println("log(9) = " + arithmetic.log(9)) println("log(0) = " + arithmetic.log(0)) println("isPrime(23) = " + arithmetic.isPrime(23)) println("isPrime(59) = " + arithmetic.isPrime(59)) println("isPrime(75) = " + arithmetic.isPrime(75)) }
If Mathematics is the queen of the sciences, then Number Theory (aka arithmetic) is the queen of mathematics. Number theory studies the natural numbers (aka the unsigned integers: 0, 1, 2, 3, ...). The focus of number theory is on division and remainders. Complete the implementation of arithmetic.scala. Test it with the app arithTest.scala. Here's the expected output: god (15, 12) = Some (3) lcm (15, 12) Some (60) gcd (13, 12) Some (1) gcd (-13, 12) = None phi (9) = Some (6) sqrt (49) Some (7) sqrt (37) Some (6) sqrt (35) Some (5) log (64) Some (6) log (130) Some (7) log (9) Some (3) log (0) None isPrime (23) = Some (true) isPrime (59) = Some (true) isPrime (75) = Some (false) = = = If Mathematics is the queen of the sciences, then Number Theory (aka arithmetic) is the queen of mathematics. Number theory studies the natural numbers (aka the unsigned integers: 0, 1, 2, 3, ...). The focus of number theory is on division and remainders. Complete the implementation of arithmetic.scala. Test it with the app arithTest.scala. Here's the expected output: god (15, 12) = Some (3) lcm (15, 12) Some (60) gcd (13, 12) Some (1) gcd (-13, 12) = None phi (9) = Some (6) sqrt (49) Some (7) sqrt (37) Some (6) sqrt (35) Some (5) log (64) Some (6) log (130) Some (7) log (9) Some (3) log (0) None isPrime (23) = Some (true) isPrime (59) = Some (true) isPrime (75) = Some (false) = = = Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
