[erlang-questions] [Erlang-Question] Is Erlang good for Matrix manipulation and AI related algorithms
Thu Nov 17 09:09:21 CET 2011
Thank you for your links, but the formula is seemingly not right!
The number of paths to [n,m,k] should equals to (n+m+k)! / (n!*(m+k)!).
I write down a snippet of erlang cold as following. Please correct me if I
did it in an inefficient way.
-export([build/1]). %%One list as argument specifying the dimensions of
build([H|], D) ->
build_innerlist(H, D,  );
build([H|T], D) ->
Bu = fun(X) -> build(T, [X|D]) end, %%Any better way here?
build_outterlist(H, Bu, ).
build_innerlist(0, _D, L) ->
build_innerlist(N, D, L) when N > 0 ->
[factorial(N+lists:sum(D))/(factorial(N)*factorial(lists:sum(D))) | L]).
build_outterlist(0, _X, L) ->
build_outterlist(N, X, L) when N > 0 ->
build_outterlist(N-1, X, [X(N)|L]).
factorial(N) when N > 0 ->
factorial(0, V) ->
factorial(N, V) ->
Eshell V5.8.4 (abort with ^G)
On Thu, Nov 17, 2011 at 12:33 AM, Peer Stritzinger <peerst@REDACTED> wrote:
> Forget what I said about Catalan Numbers (these count paths staying
> below the diagonal).
> What you need is this: http://mathworld.wolfram.com/LatticePath.html
> From this you could easily derive that the number of paths in a n x m
> x k cuboid is:
> (n+m+k)! / (n!*m!*k!)
> Well that was easier than I thought.
> -- Peer
> On Tue, Nov 15, 2011 at 6:19 AM, Barco You <barcojie@REDACTED> wrote:
> > Hi Peer,
> > Could you please show me the one-line operation in erlang? Thank you!
> > Regards,
> > Barco
> > On Tue, Nov 15, 2011 at 1:18 PM, Peer Stritzinger <peerst@REDACTED>
> >> On Thu, Nov 10, 2011 at 6:39 AM, Barco You <barcojie@REDACTED> wrote:
> >> > I hope to know there are how many paths across a specific point in a
> >> > cubic
> >> > lattice if we walk from the origin to the far-most diagonal point.
> >> It is not difficult to derive a closed form for this number, then
> >> It'll be a fast O(1) operation in one line in any language.
> >> Cheers,
> >> -- Peer
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions