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@mail.gap-system.org
http://mail.gap-system.org/mailman/listinfo/forum



_______________________________________________
Forum mailing list
Forum@mail.gap-system.org
http://mail.gap-system.org/mailman/listinfo/forum

Reply via email to