Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started