1. RE: Slice sequence--new algorithm
- Posted by Al Getz <Xaxo at aol.com> Feb 21, 2001
- 404 views
Lutz & Juri: Hi Juri, Nice algorithm! I think i'll use that one myself. Since now your in the mood, perhaps you would care to generalize one step further: Adapt your algorithm to handle an arbitrarily complex sequence. The time factor has stumped me a bit, as elements wont be the same in all locations in the sequence, therefore sometimes a larger element will replace a smaller element, which brings in a longer time cost factor. If there was some way around that... Perhaps recursion would help for the more complex case, even if it takes more time to complete, which brings a second question to mind which ill ask in a separate post about recursion and memory resources. Hi Lutz, Thanks for your insight! Lutz wrote: >>Yes, but nowadays time is more valuable than memory space! Time isnt always independent of memory: if you get low on memory and windows resorts to disk swapping, it could take 10x longer to run then a more complicated program that doesnt use up all the ram in the system. >>What do you think EUPHORIA does internally? Check out Rob's response to the thread. Have fun with it! --Al
2. RE: Slice sequence--new algorithm
- Posted by Al Getz <Xaxo at aol.com> Feb 21, 2001
- 387 views
Hi Derek, You reminded me of a routine i coded quite a while back and forgot about! All i used it for was to remove spaces. It should be quite fast for low target char to other char ratios. Here it is: --removes all occurances of n from s: p=find(n,s) while p do s=s[1..p-1]&s[p+1..length(s)] p=find(n,s) end while Too bad Euphoria doesnt allow 'while (p=find(n,s))>0' or it would shorten the routine even more: --cant do this in euphoria? while p=find(n,s) do s=s[1..p-1]&s[p+1..length(s)] end while Have fun with it! --Al
3. RE: Slice sequence--new algorithm
- Posted by Al Getz <Xaxo at aol.com> Feb 21, 2001
- 376 views
Hi Juri, jbabor at PARADISE.NET.NZ wrote: > Al, did you have something like the following function in mind? > > jiri > > > function remove(sequence s, object n) > object si > integer p > > p = 0 > for i = 1 to length(s) do > si = s[i] > if compare(si, n) then > if sequence(si) then > si = remove(si, n) > end if > p += 1 > s[p] = si > end if > end for > return s[1..p] > end function > > Yes exactly! Now im trying to determine what the memory overhead is when a function is called in order to determine what sequence dimension depth can be handled without the occurance of disk swapping. As you probably know, each call must replicate the data required for a single call on some sort of stack. Quick prelim tests show at least 25 bytes not including other private variables. This could be significant with some larger sequences because all that data has to be kept untill the last return is encountered. I hope to learn more about this. In the mean time, small or medium sized sequences, or larger ones that arent too lopsided should work fine. Good luck with it. --Al