Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created August 25, 2013 16:56
Show Gist options
  • Save chris-martin/6334969 to your computer and use it in GitHub Desktop.
Save chris-martin/6334969 to your computer and use it in GitHub Desktop.
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