Re: Elementary but surprisingly difficult.
- From: Albert van der Horst <albert@xxxxxxxxxxxxxxxxxx>
- Date: 25 May 2008 11:43:50 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
----------------------------------------------
WANT CASE-INSENSITIVE CASE-INSENSITIVE
WANT TUCK
WANT BOUNDS
WANT DUMP
CREATE AAP 1 C, 1 C, 2 C, 2 C, 3 C, 4 C, 5 C, 5 C, 5 C, 5 C,
: 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 - ;
AAP 10 uniquify .
AAP 100 DUMP
----------------------------------------------
albert@apple:~/PROJECT/euler> lina -a
"unique.frt" INCLUDED
4
0805,124C: 0102 0304 |....|
0805,1250: 0504 0505 0505 0000 0800 0000 756E 6971 |............uniq|
0805,1260: 7569 6679 68A7 0408 8012 0508 0000 0000 |uifyh...........|
0805,1270: 2C12 0508 5812 0508 0A05 0508 0000 0000 |,...X...........|
0805,1280: 98A3 0408 B8A1 0408 740A 0508 48A4 0408 |........t...H...|
0805,1290: 48A4 0408 98A5 0408 A8A4 0408 E4AF 0408 |H...............|
0805,12A0: 2C99 0408 3400 0000 6899 0408 98A5 0408 |,...4...h.......|
OK
BYE
----------------------------------------------
So is this a bug in lina, or does it fail the first test
I throw at it?
(I expect 5 of course.)
The code is not transparent enough that it would be of
any value as specification of an algorithm, or in this
case to debug.
--
Bernd Paysan
Groetjes Albert
--
--
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
|