Skip to content

Instantly share code, notes, and snippets.

View cedricbastin's full-sized avatar
🇨🇭
Grüezi Schwiiz

Cédric Bastin cedricbastin

🇨🇭
Grüezi Schwiiz
View GitHub Profile
@cedricbastin
cedricbastin / GroupBy.scala
Created February 2, 2016 19:12
Databricks coding challenge
//sbt run
//or
//scalac GroupBy.scala; scala GroupByRun
import java.util.UUID
import scala.collection.immutable.HashMap
import scala.util.Random
import java.io._
/**
@cedricbastin
cedricbastin / Pascal.scala
Last active December 8, 2015 07:27
The Pascal triangle implemented recursively by it's cell relation definition using lazy scala streams
import scala.collection.immutable.Stream
//create the Pascal triangle using scala Streams
object Pascal extends App {
def plus(a:Int, b:Int) = a+b
def map2(str:Stream[Int], f:(Int, Int) => Int):Stream[Int] = str match { //pattern matcher doesn't seem to work properly
case Stream.Empty => str
case _ #:: Stream.Empty => str
case a #:: tail => f(a, tail.head) #:: map2(tail, f)
@cedricbastin
cedricbastin / RepMin.scala
Last active August 29, 2015 14:18
exploring lazy evaluation to avoid multiple passes over a tree
object Main extends App {
/*
* Exploring lazy evaluation in Scala to replace all nodes in a tree with the minimum value of the tree in 1 pass
* thanks to @begeric
*/
sealed trait Tree
case class Node(tl:Tree, v:Int, t2:Tree) extends Tree
case object Leaf extends Tree
/*
* we give a concrete tree as input and a lazy value min which will eventually contain the minimum of all nodes