Re: Elementary but surprisingly difficult.



In article <ebemg5-rae.ln1@xxxxxxxxxxxxxxxx>,
Bernd Paysan <bernd.paysan@xxxxxx> wrote:
Slava Pestov wrote:

On May 24, 3:05 pm, Albert van der Horst <alb...@xxxxxxxxxxxxxxxxxx>
wrote:
Even using variables/locals, I find this difficult.
(More difficult then e.g. making a table for the number of
dividers of N, which sounds much less trivial.)

It's not difficult if you have a library of sequence operations:

Nice filter, but doing that in-place is not difficult, either.

I give you a solution for characters in a string, and Albert can generalize
it. It is supposed that the string is sorted, so it will only remove
sequenes of the same character:

: uniquify ( addr u -- addr u' )
over >r bounds dup dup c@ 2swap 1+ ?DO
I c@ tuck <> IF swap 1+ 2dup c! swap THEN LOOP
drop r> swap over - ;

The main problem is that the content cannot be placed
on the stack they cannot be compared with <> etc.
The above solution foregoes the technical problem.
The algorithmic solution you gave is of course easy enough to come up
with. Although it looks ugly enough even for this simple case.


--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/


--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

.



Relevant Pages

  • Re: Problems with TIB again, I think
    ... parse dup>r ... swap cmove (move string to one cell after here) ... r> allot align (get count and allocate mem for string, ...
    (comp.lang.forth)
  • Re: Elementary but surprisingly difficult.
    ... Albert van der Horst, UTRECHT,THE NETHERLANDS ... 2dup c@ swap c@ ... 2dup c@ dup rot c! ...
    (comp.lang.forth)
  • [SLE] Faulty memory reports from net-snmp on 9.1
    ... enterprises.ucdavis.memory.memSwapErrorMsg.0 = STRING: Running out of swap space ... VmallocChunk: 416112 kB ...
    (SuSE)
  • Re: Using ref
    ... If the parameter were passed by reference by default, ... To demonstrate that for most stuff, except for swap, 'new' and stuff ... As you can see for the string passing by reference ... public void FooClassSB1 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Elementary but surprisingly difficult.
    ... Albert van der Horst, UTRECHT,THE NETHERLANDS ... 2dup c@ swap c@ ... 2dup c@ dup rot c! ...
    (comp.lang.forth)