Get multi-dimension array length in Karel

  • I am using undetemined two dimension array as Routine input parameter, e.g, to do matrix multiply operation, I need to know the length of A,B before FOR...ENDFOR.

    I try to use built-ins ARRAY_LEN() to do this, but it turns out it only return the length of first dimension. so is there any way to get it`s two dimension length of array?


    --MULIPLICATION

    ROUTINE ARY_MULT(A,B:ARRAY [*,*] OF REAL ):ARRAY [*,*] OF REAL

    VAR

    C:ARRAY [*,*] OF REAL

    l:INTEGER

    BEGIN

    l = ARRAY_LEN(A)

    --A first dimension length

    FOR i =1 TO l DO

    --B second dimension length

    FOR j =1 TO l DO

    C[i,j]=0

    --A second dimension length

    FOR k=1 TO l DO

    C[i,j]=C[i,j]+A[i,k]*B[k,j]

    ENDFOR

    ENDFOR

    ENDFOR

    RETURN (C)


    END ARY_MULT



    thanks

  • Place your Ad here!
  • massula

    Approved the thread.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now

Advertising from our partners