[erlang-questions] [Erlang-Question] Is Erlang good for Matrix manipulation and AI related algorithms
Peer Stritzinger
<>
Wed Nov 16 16:59:58 CET 2011
On Tue, Nov 15, 2011 at 6:19 AM, Barco You <> wrote:
> Hi Peer,
> Could you please show me the one-line operation in erlang? Thank you!
Sorry can't do your work for you. But I have some hints:
A closed form solution will look similar than the Catalan Number
(amongst other uses = number of monotonic paths in a nxn grid)
http://en.wikipedia.org/wiki/Catalan_number
If you google for catalan numbers you can probably find an example how
the formula for the nxn grid is derived.
Extend this first to n x m grids then to n x m x k
Number of monotonic paths through a given point:
path_count_from_origin_to_point * path_count_from_point_to_nmk, the
two counts you can calculate with the n x m x k formula you derived
above (= number of paths to the sub-cuboids)
Write the formula in one Erlang line done.
If you want your computer do at least some of the work for you go with
Jespers suggestion. http://en.wikipedia.org/wiki/Dynamic_programming
Some suggestions how to approach this:
function cuboid_paths(N, M, K) ->
1. cut the cuboid along its largest dimension in two halves (lets say
N) Cut = N/2
2. sum for all points in the cut (M1, K1)
2a. recursively call cuboid function to get paths to the point and
paths from the point and multiply: cuboid_paths(Cut, M1, K1) *
cuboid_paths(N-Cut, M-M1, K-K1)
Define the border cases you have the function.
This is not yet optimal, but you can use dynamic programming (see
above) to get a solution that avoids recalculation. Left as exercise
for the reader ;-)
Cheers
-- Peer
>
> Regards,
> Barco
>
> On Tue, Nov 15, 2011 at 1:18 PM, Peer Stritzinger <> wrote:
>>
>> On Thu, Nov 10, 2011 at 6:39 AM, Barco You <> 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
>
>
More information about the erlang-questions
mailing list