Skip to content

Commit

Permalink
coprime
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed Mar 15, 2012
1 parent 91e4588 commit 179dd75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/s99/ArithmeticSolutions.scala
Expand Up @@ -12,7 +12,7 @@ trait ArithmeticSolutions {
def isPrime: Boolean =
n == 1 || n == 2 || (2 to n/2).forall(n % _ != 0)

def isCoprimeTo(n: Int): Boolean = ???
def isCoprimeTo(other: Int): Boolean = gcd(n, other) == 1
def totient: Int = ???
def improvedTotient: Int = ???
def primeFactors: List[Int] = ???
Expand Down
5 changes: 3 additions & 2 deletions src/test/scala/s99/ArithmeticSpec.scala
Expand Up @@ -14,7 +14,7 @@ class ArithmeticSpec extends Specification with ArithmeticSolutions {

""" Determine whether two positive integer numbers are coprime
Two numbers are coprime if their greatest common divisor equals 1""" >>
{ 35.isCoprimeTo(64) must beTrue }
{ 35 must beCoprimeTo(64) }

""" Calculate Euler's totient function phi(m)
Euler's so-called totient function phi(m) is defined as the number of positive integers r (1 <= r <= m) that are
Expand Down Expand Up @@ -75,5 +75,6 @@ class ArithmeticSpec extends Specification with ArithmeticSolutions {
"1856 = 67 + 1789",
"1928 = 61 + 1867") }

def bePrime: Matcher[Int] = (i: Int) => (i.isPrime, i+" is prime", i+" is not prime")
def bePrime: Matcher[Int] = (i: Int) => (i.isPrime, i+" is not prime")
def beCoprimeTo(j: Int): Matcher[Int] = (i: Int) => (i.isCoprimeTo(j), i+" is not coprime to"+j)
}

0 comments on commit 179dd75

Please sign in to comment.