I don't think this is a bug. main calls is_ok, which clobbers the variable k. If you change it to use lexical scoping:

is_ok(n)=
{
  my(sums=0, k=n, t=1); \\ <-- key change
  while(i!=-1 && t<k,
    if(sums>11,
      i=-1
    ,
      if(n-t^2<=t^2 && issquare(n-t^2),
        sums++
      )
    );
    t++
  );
  sums;
}

this should work as intended.

Charles Greathouse
Analyst/Programmer
Case Western Reserve University