{{ message }}

Instantly share code, notes, and snippets.

# Jason Liszka jliszka

Last active Nov 30, 2018
View mystery.scala
 // Multinomial formula def multi(ks: Vector[Int]): Double = { (1 to ks.sum) .map(_ / ks.size.toDouble) .zip(ks.flatMap(1 to _)) .map({ case (n, d) => n / d }).product } // Expected number of cereal boxes you have to buy if you want to collect at least `m` of each of `n` surprise mystery toys def e(n: Int, m: Int, M: Int = 20, v: Vector[Int] = Vector.empty): Double = {
Last active Jan 18, 2016
 def basketball(unseenShots: Int) = { def prob(outcomes: List[Boolean]) = 1.0 * outcomes.count(m => m) / outcomes.size val outcomes = always(List(true, false)).markov(unseenShots+1)(outcomes => tf(prob(outcomes)).map(b => b::outcomes)).given(_.head) val lastShot = for { outcome <- outcomes shot <- tf(prob(outcome)) } yield shot lastShot.pr(a => a) }
Created Jan 12, 2016
View car.py
 from itertools import permutations import pprint class Strategy: def cards(self, cs): return False def filter(self, p): return True
Last active Aug 29, 2015
View JavaEmbeddedRecord.java
 class JavaEmbeddedRecord { public UserId getId() { return (UserId)(new Long(5)); } }
Last active Aug 29, 2015
View benchmarks.scala
 import scala.collection.mutable.WrappedArray abstract class Impl(val name: String) { val N = 20000 val R = 100 def setup(n: Int): Unit = () def run(n: Int): Unit
Last active Dec 31, 2015
Code for "Bayesian models and causality"
View Examples.scala
 /* Setup: \$ git clone https://github.com/jliszka/probability-monad.git \$ cd probability-monad \$ ./sbt console scala> :load Examples.scala */ import probability_monad._ import probability_monad.Distribution._
Created Nov 15, 2013
View primes.hs
 import Data.List import Test.QuickCheck import qualified Data.Map as Map nats = [1..] divides a b = b `mod` a == 0 sieve (n:t) m = case Map.lookup n m of Nothing -> n : sieve t (Map.insert (n*n) [n] m) Just ps -> sieve t (foldl reinsert (Map.delete n m) ps) where
Last active Oct 1, 2016
View foursquare.hs
 import Data.List import Test.QuickCheck import qualified Data.Map as Map nats = [1..] divides a b = b `mod` a == 0 sieve (n:t) m = case Map.lookup n m of Nothing -> n : sieve t (Map.insert (n*n) [n] m) Just ps -> sieve t (foldl reinsert (Map.delete n m) ps) where
Created Oct 31, 2013
View Poly.scala
 class Poly(coeffs: Int => Double) { // Memoizing coefficient accessor. Returns the coefficient for x^n. def apply(n: Int): Double = memo.getOrElseUpdate(n, this.coeffs(n)) // The memo table private val memo = scala.collection.mutable.HashMap[Int, Double]() def +(that: Poly): Poly = new Poly(n => this(n) + that(n))
Last active Sep 3, 2020
View Dual.scala
 abstract class Dual(val rank: Int) { self => // Cell value accessor protected def get(r: Int, c: Int): Double // Memoizing cell value accessor def apply(r: Int, c: Int): Double = memo.getOrElseUpdate(r - c, self.get(r, c)) // The memo table