Re: Elementary but surprisingly difficult.
- From: Albert van der Horst <albert@xxxxxxxxxxxxxxxxxx>
- Date: 25 May 2008 09:36:32 GMT
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
.
- Follow-Ups:
- Re: Elementary but surprisingly difficult.
- From: Bernd Paysan
- Re: Elementary but surprisingly difficult.
- References:
- Elementary but surprisingly difficult.
- From: Albert van der Horst
- Re: Elementary but surprisingly difficult.
- From: Slava Pestov
- Re: Elementary but surprisingly difficult.
- From: Bernd Paysan
- Elementary but surprisingly difficult.
- Prev by Date: Re: Elementary but surprisingly difficult.
- Next by Date: Re: Elementary but surprisingly difficult.
- Previous by thread: Re: Elementary but surprisingly difficult.
- Next by thread: Re: Elementary but surprisingly difficult.
- Index(es):
Relevant Pages
|