This file contains 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
import org.scalacheck.Gen | |
import org.scalatest.{ShouldMatchers, FlatSpec} | |
import org.scalatest.prop.PropertyChecks | |
class AllocatorTest extends FlatSpec with ShouldMatchers with PropertyChecks { | |
val positives = Gen.posNum[Int] | |
val vectorOfPositives = Gen.nonEmptyContainerOf[Vector, Int](positives) | |
"A proportional distribution" should "have the same amounts as weights" in { |
This file contains 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
import System.Environment | |
import System.Exit | |
import System.Random | |
import System.IO | |
data Feedback = Smaller | Bigger | Done deriving (Show, Eq) | |
type Guess = Int | |
type Range = (Int, Int) | |
range = (1, 100) |
This file contains 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
import Control.Monad.Random | |
import Data.List | |
import System.Environment | |
import System.Exit | |
import System.Random | |
import System.IO | |
data Feedback = Smaller | Bigger | Done deriving (Show, Eq) | |
type Guess = Int | |
type Range = (Int, Int) |
This file contains 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
import scalaz.syntax.std.boolean._ | |
boolExpression.option(computingSomethingComplicated) |
This file contains 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
package bowling | |
class Game { | |
trait Line { | |
def addRoll(pins: Int): Unit | |
def score: Int | |
} | |
class Frame(next: Line) extends Line { |
This file contains 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
import akka.actor._ | |
object SimpleSieve extends App { | |
val MaxNumber = 500000 | |
case object NoMoreCandidates | |
class Filter extends Actor { |
This file contains 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
import akka.actor._ | |
object BackPressureSieve extends App { | |
val DefaultChunkSize = 1024 | |
val MinChunkSize = DefaultChunkSize * 3 / 4 | |
val MaxNumber = 500000 | |
case object GetCandidates | |
case class Candidates(values: Vector[Int]) |
This file contains 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
class Sieve(maxNumber: Int) { | |
private val candidates = Array.fill(maxNumber + 1)(true) | |
def run(): Unit = { | |
for (index <- 2 to maxNumber) { | |
if (candidates(index)) { | |
crossOutMultiples(index) | |
} | |
} | |
} |
This file contains 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
package distro | |
import scala.annotation.tailrec | |
import scala.util.Random | |
trait Distro[A] { | |
def eventSet: Set[A] | |
def probOf(event: A): BigDecimal | |
def map[B](f: A => B): Distro[B] | |
def flatMap[B](f: A => Distro[B]): Distro[B] |
This file contains 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
package lines | |
import java.io.File | |
import scala.annotation.tailrec | |
object LineCount { | |
def of(file: File): Int = { | |
val source = scala.io.Source.fromFile(file) | |
try of(source.toStream) |
OlderNewer