Hi Peer,<div><br></div><div>Thank you for your links, but the formula is seemingly not right!</div><div><br></div><div>The number of paths to [n,m,k] should equals to (n+m+k)! / (n!*(m+k)!).</div><div><br></div><div>I write down a snippet of erlang cold as following. Please correct me if I did it in an inefficient way.</div>
<div><br></div><div><div>-module(lattice).</div><div><br></div><div>-export([build/1]). %%One list as argument specifying the dimensions of the lattice</div><div><br></div><div>build([]) -></div><div> [];</div>
<div>build([H|T]) -></div><div> build([H|T], []).</div><div><br></div><div>build([H|[]], D) -></div><div> build_innerlist(H, D, [] );</div><div>build([H|T], D) -></div><div> Bu = fun(X) -> build(T, [X|D]) end, %%Any better way here?</div>
<div> build_outterlist(H, Bu, []).</div><div><br></div><div>build_innerlist(0, _D, L) -></div><div> L;</div><div>build_innerlist(N, D, L) when N > 0 -></div><div> build_innerlist(N-1, D, [factorial(N+lists:sum(D))/(factorial(N)*factorial(lists:sum(D))) | L]).</div>
<div><br></div><div>build_outterlist(0, _X, L) -></div><div> L;</div><div>build_outterlist(N, X, L) when N > 0 -></div><div> build_outterlist(N-1, X, [X(N)|L]).</div><div><br></div><div>factorial(0) -></div>
<div> 1;</div><div>factorial(N) when N > 0 -></div><div> factorial(N,1).</div><div><br></div><div>factorial(0, V) -></div><div> V;</div><div>factorial(N, V) -></div><div> factorial(N-1, N*V).</div>
</div><div><br></div><div><br></div><div><div>Eshell V5.8.4 (abort with ^G)</div><div>1> lattice:build([2,2,2]).</div><div>[[[3.0,6.0],[4.0,10.0]],[[4.0,10.0],[5.0,15.0]]]</div></div><div><br></div><div> <br><br><div class="gmail_quote">
On Thu, Nov 17, 2011 at 12:33 AM, Peer Stritzinger <span dir="ltr"><<a href="mailto:peerst@gmail.com" target="_blank">peerst@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Forget what I said about Catalan Numbers (these count paths staying<br>
below the diagonal).<br>
<br>
What you need is this: <a href="http://mathworld.wolfram.com/LatticePath.html" target="_blank">http://mathworld.wolfram.com/LatticePath.html</a><br>
<br>
>From this you could easily derive that the number of paths in a n x m<br>
x k cuboid is:<br>
<br>
(n+m+k)! / (n!*m!*k!)<br>
<br>
Well that was easier than I thought.<br>
<span><font color="#888888">-- Peer<br>
</font></span><div><div><br>
On Tue, Nov 15, 2011 at 6:19 AM, Barco You <<a href="mailto:barcojie@gmail.com" target="_blank">barcojie@gmail.com</a>> wrote:<br>
> Hi Peer,<br>
> Could you please show me the one-line operation in erlang? Thank you!<br>
><br>
> Regards,<br>
> Barco<br>
><br>
> On Tue, Nov 15, 2011 at 1:18 PM, Peer Stritzinger <<a href="mailto:peerst@gmail.com" target="_blank">peerst@gmail.com</a>> wrote:<br>
>><br>
>> On Thu, Nov 10, 2011 at 6:39 AM, Barco You <<a href="mailto:barcojie@gmail.com" target="_blank">barcojie@gmail.com</a>> wrote:<br>
>><br>
>> > I hope to know there are how many paths across a specific point in a<br>
>> > cubic<br>
>> > lattice if we walk from the origin to the far-most diagonal point.<br>
>><br>
>> It is not difficult to derive a closed form for this number, then<br>
>> It'll be a fast O(1) operation in one line in any language.<br>
>><br>
>> Cheers,<br>
>> -- Peer<br>
><br>
><br>
</div></div></blockquote></div><br></div>