This file contains hidden or 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
require "big_int" | |
def fact(n) | |
return 1 if n == 0 | |
n * fact(n - 1) | |
end | |
n = BigInt.new(ARGV[0]) | |
puts fact(n) |
This file contains hidden or 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
from functools import reduce | |
from itertools import groupby | |
from operator import (itemgetter,add) | |
def reduceByKey(func, iterable): | |
"""Reduce by key. | |
Equivalent to the Spark counterpart | |
Inspired by http://stackoverflow.com/q/33648581/554319 |
This file contains hidden or 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 akka.actor._ | |
import akka.routing.RoundRobinRouter | |
import akka.util.Duration | |
import akka.util.duration._ | |
sealed trait PiMessage | |
case object Calculate extends PiMessage | |
case class Work(start: Int, nrOfElements: Int) extends PiMessage | |
case class Result(value: Double) extends PiMessage | |
case class PiApproximation(pi: Double, duration: Double) extends PiMessage |
This file contains hidden or 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 week6 | |
import scala.io.Source | |
object collections { | |
/* read a file of words */ | |
val in = Source.fromURL("http://lamp.epfl.ch/files/content/sites/lamp/files/teaching/progfun/linuxwords.txt") | |
/* create a list and filter all words where *all* their characters are not letters (like dashes) */ | |
val words = in.getLines.toList filter (word => word forall (chr => chr.isLetter)) |
This file contains hidden or 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
""""Create "The Matrix" of binary numbers scrolling vertically in your terminal. | |
original code adapted from juancarlospaco: | |
- http://ubuntuforums.org/showpost.php?p=10306676 | |
Inspired by the movie: The Matrix | |
- Corey Goldberg (2013) | |
Requires: |