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 xmas | |
object Tree { | |
def apply(n: Int) = { | |
val width = n * 2 - 1 | |
def center(line: String) = { | |
val padding = " " * ((width - line.length) / 2) | |
padding ++ line ++ padding | |
}.mkString | |
def line(row: Int) = row * 2 + 1 |
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub locs { | |
my $repo = shift; | |
`sloccount $repo | grep ^java` =~ /^java:\s+(\d+)/; | |
return $1; | |
} |
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 scala.io.Source | |
import scala.collection.mutable | |
object ImperativeIndentationCheck { | |
def isValid(filename: String): Boolean = isValid(Source.fromFile(filename).getLines.toSeq) | |
def isValid(lines: Seq[String]): Boolean = { | |
val scopes = mutable.Stack(0) | |
for(line <- lines) { |
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 scala.io.Source | |
object IndentationCheck { | |
def isValid(filename: String): Boolean = isValid(Source.fromFile(filename).getLines.toSeq) | |
def isValid(lines: Seq[String]): Boolean = { | |
val initialAccum: Option[Set[Int]] = Some(Set(0)) | |
lines.map(indentationOf).foldLeft(initialAccum) { (accum, i) => | |
accum match { |
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 berlin | |
object BerlinClock { | |
sealed trait Light | |
case object Off extends Light | |
case object Yellow extends Light | |
case object Red extends Light | |
type Clock = List[List[Light]] |
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 { |