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
case class Point(x: Double, y: Double) { | |
def +(p: Point) = Point(x + p.x, y + p.y) | |
def *(a: Double) = Point(a * x, a * y) | |
def distTo(that: Point) = { | |
val Point(dx, dy) = this + that * -1 | |
math.sqrt(dx * dx + dy * dy) | |
} | |
} |
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
val integers = Stream.from(0) | |
object E1 { | |
val evenIntegers = integers.filter(_ % 2 == 0) | |
} | |
object E2 { | |
val evenIntegers = integers.map(_ * 2) | |
} | |
object E3 { |
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
sealed trait Move | |
case class Spin(x: Int) extends Move | |
case class Exchange(a: Int, b: Int) extends Move | |
case class Partner(a: Char, b: Char) extends Move | |
object Move { | |
val spin = """s(\d+)""".r | |
val exchange = """x(\d+)/(\d+)""".r | |
val partner = """p(\w)/(\w)""".r | |
val fromString: PartialFunction[String, Move] = { | |
case spin(x) ⇒ Spin(x.toInt) |
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
#!/bin/bash | |
die () { | |
echo "$1" | |
exit 1 | |
} | |
get-scala-version () { | |
curl http://www.scala-lang.org/ 2> /dev/null | grep scala-version | perl -pe 's/\D*([0-9.]+)\D*/$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
val rut1 = 15666777 // - 3 | |
val rut2 = 23456789 // - 6 | |
val rut3 = 22333444 // - k | |
// 1 5 6 6 6 7 7 7 | |
// ...3 2 7 6 5 4 3 2 | |
// 3 10 42 36 30 28 21 14 → (+) → 184 | |
// -184 mod 11 = 3 |
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
////////////////////////////////////////////////// | |
// // | |
// El patrón del match // | |
// // | |
// Roberto Bonvallet // | |
// @rbonvall // | |
// // | |
// Martes 17 de mayo de 2016 // | |
// Santiago Scala Meetup // | |
// // |
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
////////////////////////////////////////////////// | |
// // | |
// El patrón del match // | |
// // | |
// Roberto Bonvallet // | |
// @rbonvall // | |
// // | |
// Martes 17 de mayo de 2016 // | |
// Santiago Scala Meetup // | |
// // |
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
// Unos tipos con opciones // | |
// // | |
// Roberto Bonvallet // | |
// @rbonvall // | |
// // | |
// Viernes 1 de abril de 2016 // | |
// Santiago Scala Meetup // |
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 python | |
from numpy import * | |
#r = raw_input() | |
r = 'Programming Puzzles & Code Golf' | |
s = sign(diff(map(ord, r[0] + r))) | |
c = cumsum(s) | |
p = 2 * (max(c) - c) + 1 | |
w = max(p) + 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
object f { | |
val floatingPointNumberPattern = """(\d+(?:[.]\d*))""".r | |
def unapply(s: String): Option[Double] = s match { | |
case floatingPointNumberPattern(x) ⇒ Some(x.toDouble) | |
case _ ⇒ None | |
} | |
} | |
object i { | |
val nonNegativeIntegerPattern = """(\d+)""".r |
NewerOlder