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.

   The AfterBeat

Irv Mullins wrote:

> -- Here's code that creates a list of coordinates,
> -- and then deletes each n-th element of that list
> -- I would like some feedback on a more Euphorish
> -- way to accomplish the task. Any takers?
> -- Thanks, Irv
>
> include get.e
> constant n = 4, -- each n-th element
>          scrn = 1
>
> sequence dyn_list, new_list
>          dyn_list = {} -- create an empty dynamic list
>          new_list = {}
>
> function GetCoords()
> integer x,y
>    x = prompt_number("Coord X:",{1,640})
>    y = prompt_number("Coord Y:",{1,480})
>    return({x,y})
> end function
>
> function delete(sequence list, integer item)
> return list[1..item-1] & list[item+1..length(list)]
> end function
>
> dyn_list = {GetCoords()} -- get the first set of coords
> while 1 do
>     dyn_list = append(dyn_list,GetCoords()) -- get the next coords
>     ? dyn_list
>      if match(dyn_list[1], dyn_list[length(dyn_list)]) then -- compare first
>      and last list items
>         exit -- quit when equal
>      end if
>  end while
>
> printf(scrn,"You have entered %d items\n",length(dyn_list))
> printf(scrn,"Now removing each %dth item\n",n)
> puts(scrn,"Before: ") ? dyn_list
> -----------------------------------
> -- Here's where I need some help.--
> -- Isn't there a more Euphorish  --
> -- way to do this? Maybe without --
> -- duplicating sequences and so  --
> -- tying up more memory?   Tnx   --
> -----------------------------------
> for i = 1 to length(dyn_list) do
>     if remainder(i,n) then
>        new_list = append(new_list,dyn_list[i])
>     end if
> end for
> puts(scrn,"After: ") ? new_list

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

Search



Quick Links

User menu

Not signed in.

Misc Menu