[GAP Forum] Need Help with first gap code

Benjamin Sambale benjamin.sambale at gmail.com
Thu Nov 14 21:40:35 GMT 2013


A short answer: lists start with 1 in GAP, i.e. L[0] is not allowed.

Best,
Benjamin

Am 14.11.2013 22:26, schrieb sam johnson:
> Hey guys I'm new to this forum and i need help with my code. My code should
> basically return the position of the maximum element in the list which is
> quite easy the problem that it keeps giving me the following message and
> I'm sure the logic of the code is correct.
>
> Code:
> whereismax := function(L)
>      local x, maxpos;
>      maxpos := 0;
>      for x in [1..Size(L)-1]do
>           if  L[x] > L[maxpos] then
>              maxpos :=  x;
>           fi;
>      od;
>      return maxpos;
> end;
>
>
> Error message:
> Error, no method found! For debugging hints type ?Recovery from
> NoMethodFound
> Error, no 1st choice method found for `[]' on 2 arguments called from
> Size( L ) called from
> <function "whereismax">( <arguments> )
>   called from read-eval loop at line 40 of *stdin*
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum
>




More information about the Forum mailing list