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 upperBound = 100 | |
val candidates = sc.range(1, upperBound) | |
val factors = sc.range(1, math.sqrt(upperBound).toLong+1) | |
val primes = { | |
candidates.cartesian(factors) filter { | |
case (candidate, factor) => candidate % factor == 0L | |
} | |
}.aggregateByKey(0L)((counter, _) => counter+1L, _ + _).filter(_._2 <= 2L).keys |
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
curl https://www.eventbrite.es/e/lambda-world-2017-tickets-35032894330\#tickets \ | |
| awk -F "collection : " '{print $2}' \ | |
| jq '.[] | {ticket_type: .ticket_name, price: .cost.display, remaining: .number_of_tickets_remaining}' |
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
@tailrec | |
def permutations[T](alphabet: Set[T], s: Seq[Seq[T]] = Seq(Seq.empty[T])): Seq[Seq[T]] = | |
if(s.head.size == alphabet.size) s else { | |
val updatedSolutions = for { | |
partial <- s | |
chosen <- (alphabet -- partial) | |
} yield chosen +: partial | |
permutations(alphabet, updatedSolutions) | |
} |
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.pfcoperez.dailyalgorithm.datastructures.graphs.undirected._ | |
val ug = UndirectedGraph(Set(1,2,3,4), Edge(1,2)::Edge(2,3)::Edge(3,4)::Edge(4,1)::Nil) | |
ug.adjacentTo(1) | |
ug.adjacentTo(2) | |
ug.adjacentTo(3) | |
ug.adjacentTo(4) | |
(ug - Edge(1,4)).adjacentTo(1) | |
(ug - Edge(1,4)).adjacentTo(4) |
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 | |
function launchIteration { | |
CMD=$1 | |
STOP_OUTPUT_PATTERN=$2 | |
OUTPUT_DIR=$3 | |
REMAINING_ITERATIONS=$4 | |
if [[ $REMAINING_ITERATIONS == "0" ]]; then | |
echo "Completed launch chain" |
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 | |
curl https://www.eventbrite.es/e/lambda-world-2017-tickets-35032894330\#tickets \ | |
| awk -F "collection : " '{print $2}' \ | |
| python -m json.tool \ | |
| grep number_of_tickets_remaining |
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 cats.Monoid | |
import cats.syntax.monoid._ | |
case class Order(products: List[String], topay: Double) | |
//This could be done with higher abstraction cats tools | |
implicit val orderMonoidInstance: Monoid[Order] = new Monoid[Order] { | |
def empty: Order = Order(Nil, 0.0) | |
def combine(x: Order, y: Order): Order = Order(x.products ++ y.products, x.topay + y.topay) | |
} |
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 Solution extends App { | |
case class Trie[KE, V](v: Option[V], children: Map[KE, Trie[KE,V]]) { | |
def insert(key: Seq[KE], v: V): Trie[KE, V] = | |
if(key.isEmpty) copy(v = Some(v)) | |
else { | |
val ke = key.head | |
val newChild = children.getOrElse(ke, Trie.empty).insert(key.tail, v) | |
copy(children = children + (ke -> newChild)) | |
} |
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.util.parsing.combinator._ | |
object RobotCommands extends App { | |
object Entities { | |
trait MovementDirection | |
case object Up extends MovementDirection | |
case object Down extends MovementDirection | |
case object Left extends MovementDirection |
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
abstract class FuncStackable { | |
def f(x: Int): Int | |
} | |
class Fidentity extends FuncStackable { | |
override def f(x: Int): Int = x | |
} | |
trait NInput extends FuncStackable { | |
val n: Int |