Skip to content

Instantly share code, notes, and snippets.

Roberto Bonvallet rbonvall

Block or report user

Report or block rbonvall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rbonvall
rbonvall / ejemplos.scala
Last active Jul 13, 2018
Ejemplos meetup de Scala, 12 de julio de 2018
View ejemplos.scala
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)
}
}
@rbonvall
rbonvall / kolakoski.scala
Created Jan 12, 2018
Kolakoski prototype
View kolakoski.scala
val integers = Stream.from(0)
object E1 {
val evenIntegers = integers.filter(_ % 2 == 0)
}
object E2 {
val evenIntegers = integers.map(_ * 2)
}
object E3 {
View 16.scala
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)
View new-scala-project.sh
#!/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/'
}
@rbonvall
rbonvall / rut.scala
Created Aug 1, 2016
Dígito verificador del rut en Scala
View rut.scala
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
View 01-el-patron-del-match.scala
//////////////////////////////////////////////////
// //
// El patrón del match //
// //
// Roberto Bonvallet //
// @rbonvall //
// //
// Martes 17 de mayo de 2016 //
// Santiago Scala Meetup //
// //
View el-patron-del-match.scala
//////////////////////////////////////////////////
// //
// El patrón del match //
// //
// Roberto Bonvallet //
// @rbonvall //
// //
// Martes 17 de mayo de 2016 //
// Santiago Scala Meetup //
// //
@rbonvall
rbonvall / 01-unos-tipos-con-opciones.scala
Last active Apr 5, 2016
Charla «Unos tipos con opciones».
View 01-unos-tipos-con-opciones.scala
// Unos tipos con opciones //
// //
// Roberto Bonvallet //
// @rbonvall //
// //
// Viernes 1 de abril de 2016 //
// Santiago Scala Meetup //
View zigzagify.py
#!/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
@rbonvall
rbonvall / gist:b5f99b407af7a2709626
Created May 8, 2015
Extractors for numbers in strings
View gist:b5f99b407af7a2709626
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
You can’t perform that action at this time.