Last active
December 20, 2015 05:39
-
-
Save pH200/6080552 to your computer and use it in GitHub Desktop.
factorial generators
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
let fTable = | |
let rec factorial prev pos = seq { | |
let current = prev * pos | |
yield current | |
yield! factorial current (pos + 1) | |
} | |
factorial 1 1 |
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
let fTable = Seq.initInfinite(fun index -> Seq.reduce (*) [1..(index+1)]) |
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
function fTable() { | |
var prev = 1; | |
var pos = 1; | |
for (;;) { | |
var current = prev * pos; | |
prev = current; | |
pos++; | |
if (yield current) { | |
prev = 1; | |
pos = 1; | |
} | |
} | |
} |
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
def factorial(prev: BigInt, pos: Int): Stream[BigInt] = { | |
val current = prev * pos | |
current #:: factorial(current, pos + 1) | |
} | |
val fTable = factorial(1, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment