Created
August 25, 2013 16:56
-
-
Save chris-martin/6334969 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def bigIntToLong(bi: BigInt): Long = bi.toLong | |
case class PrimeFactor(prime: Long, cardinality: Int) { | |
lazy val value: Long = BigInt(prime) pow cardinality | |
} | |
implicit val primeFactorOrdering: Ordering[PrimeFactor] = Ordering by (_.prime) | |
case class PrimeFactorization(factors: SortedSet[PrimeFactor]) { | |
lazy val value: Long = factors.map(_.value).product | |
} | |
object PrimeFactorization { | |
def apply(pfs: PrimeFactor*): PrimeFactorization = PrimeFactorization(SortedSet(pfs: _*)) | |
def one = PrimeFactorization(PrimeFactor(1, 1)) | |
} | |
implicit class EnhancedMutableQueue[A](queue: mutable.Queue[A]) { | |
def process(f: A => Seq[A]) { while (queue.nonEmpty) queue.enqueue(f(queue.dequeue()): _*) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment