Re: Euphorize THIS!

new topic     » goto parent     » topic index » view thread      » older message » newer message

>>Erm, will this suffice?
>>
>>-- Code starts here --
>>integer  i, max
>>
>>i = 0   max = length(dyn_list)
>>for count = n to max by n do
>>   dyn_list = dyn_list[1..(count - i) - 1] & dyn_list[(count - i) +
1..length(dyn_list)]
>>   i += 1
>>end for
>>-- Code ends here --
>>
>>I tested it, and it works..  I hope this is what you want.

Excuse me, but isn't this code somewhat inefficient? The line within the
for-loop causes the *entire* list to contract at each iteration.Try the
following code. I tested it against the above and i figured that its quicker
(well at least for a 1-d sequence of integers 4000 elements long) by a
factor of about 100....
(I hope it gives the right answer!)

function nth(sequence s, integer n) -- remove each nth item from the list
 integer rem,len,c,d,p
 len=length(s)
 rem=remainder(len,n)
 c=n-1
 d=n-2
 p=n
 for i=n+1 to len - rem by n do
  s[p..p + d]=s[i..i + d]
  p+=c
 end for
 if rem then s[p..p + rem - 1] = s[len - rem + 1..len] end if
 s=s[1..p + rem - 1]
 return s
 end function

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu