home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!Germany.EU.net!news.Hamburg.Germany.EU.net!mwhh!dmhh.hanse.de!detlef
- From: detlef@dmhh.hanse.de (Detlef Mueller)
- Newsgroups: comp.sys.hp48
- Subject: Re: Cliff Stern's Little Challenges
- Distribution: world
- Message-ID: <721197246detlef.detlef@dmhh.hanse.de>
- Sender: detlef@dmhh.hanse.de
- Date: Sun, 08 Nov 92 04:34:06 GMT
- References: <Bx9D8A.3H0@iat.holonet.net> <1depklINNnpo@iskut.ucs.ubc.ca>
- Organization: Who is Organized ?
- Lines: 69
-
- In article <1depklINNnpo@iskut.ucs.ubc.ca> ochealth@unixg.ubc.ca (ochealth) writes:
- >In article <Bx9D8A.3H0@iat.holonet.net> brianw@iat.holonet.net (Brian Walsh) writes:
- >:In message <2af8cafe.2066comp.sys.hp48@hpcvbbs.cv.hp.com> Joe Horn writes:
- >:
- >:> (5) Write a program that takes as input an integer 1 through 26, and
- >:> creates that many (and no more) *local* variables 'a', 'b', 'c',
- >:> etc., and then HALTs, leaving the local variables active. Their
- >:> contents do not matter. Example: an input of 5 would create 'a',
- >:> 'b', 'c', 'd', and 'e', and nothing else.
- >:
- >:Here are two solutions:
- >:%%HP: T(3)A(D)F(.);
- >:\<< 2 * 2 +
- >:"\-> a b c d e f g h i j k l m n o p q r s t u v w x y z"
- >:1 ROT SUB "\<<HALT" + STR\->
- >:\>>
- >:100.5 bytes
- >:
- >:%%HP: T(3)A(D)F(.);
- >:\<< "\->" 1 ROT
- >: FOR i " " + i 96 + CHR +
- >: NEXT "\<<HALT" + STR\->
- >:\>>
- >:76.5 bytes
- >:
- >:Both use the technique of building a program as a string and then using
- >:STR-> to evaluate the program. The second is quite small but takes more
- >:execution time.
- >
- >But the challenge said the program had to take a single integer as input,
- >and these programs assume that there are enough arguments on the stack.
- >At least that's how I read the challenge.
-
- My 1st attemp was:
-
- %%HP: T(3)A(D)F(.);
- \<<
- "\->" SWAP
- DO
- SWAP " " +
- OVER "`" NUM + CHR +
- UNTIL
- OVER 1 - DUP NOT
- END
- DROP
- "\<<HALT" + STR\->
- \>>
- 85.5 bytes
-
- But Brians modified 2nd solution is 6 bytes shorter:
-
- %%HP: T(3)A(D)F(.);
- \<<
- "\->" 1 ROT
- FOR i
- " " +
- i "`" NUM SWAP OVER + CHR +
- NEXT
- "\<<HALT" + STR\->
- \>>
- 79.5 bytes
-
- Bye,
- 8-Detlef
- --
- +------------------------------------+--------------------------------------+
- |`What a depressingly stupid machine'| Detlef Mueller |
- | -- Marvin | detlef@dmhh.hanse.de |
- +------------------------------------+--------------------------------------+
-