Skip to content

Instantly share code, notes, and snippets.

@snahor
Last active September 21, 2017 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snahor/e7e77ffbbdf08a7a6d6fc2b207d25788 to your computer and use it in GitHub Desktop.
Save snahor/e7e77ffbbdf08a7a6d6fc2b207d25788 to your computer and use it in GitHub Desktop.
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