Last active
September 21, 2017 03:50
-
-
Save snahor/e7e77ffbbdf08a7a6d6fc2b207d25788 to your computer and use it in GitHub Desktop.
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
structure Pascal = | |
struct | |
local | |
fun nextrow row = | |
let | |
val (ns, _) = | |
foldl | |
(fn (x, (acc, prev)) => ((prev + x) :: acc, x)) | |
([], 0) | |
row | |
in | |
1 :: ns | |
end | |
in | |
fun triangle 1 = [[1]] | |
| triangle n = | |
let | |
val rows = triangle (n - 1) | |
in | |
nextrow (hd rows) :: rows | |
end | |
val row = hd o triangle | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment