Skip to content

Instantly share code, notes, and snippets.

@zerokarmaleft
Created September 10, 2014 14:14
Show Gist options
  • Save zerokarmaleft/b309bac5c1de8a9e2831 to your computer and use it in GitHub Desktop.
Save zerokarmaleft/b309bac5c1de8a9e2831 to your computer and use it in GitHub Desktop.
var Lazy = require('lazy.js');
function isHeads(x) { return x >= 0.5; }
function isTails(x) { return x < 0.5; }
function toss(n) {
var successes = Lazy.generate(function() { return Math.random(); })
.take(n)
.filter(isHeads)
.size();
return successes / n;
}
console.log(
Lazy.generate(function () { return toss(45) }).take(100).toArray()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment