home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp48 / 5623 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  2.4 KB

  1. Path: sparky!uunet!mcsun!Germany.EU.net!news.Hamburg.Germany.EU.net!mwhh!dmhh.hanse.de!detlef
  2. From: detlef@dmhh.hanse.de (Detlef Mueller)
  3. Newsgroups: comp.sys.hp48
  4. Subject: Re: Cliff Stern's Little Challenges
  5. Distribution: world
  6. Message-ID: <721197246detlef.detlef@dmhh.hanse.de>
  7. Sender: detlef@dmhh.hanse.de
  8. Date: Sun, 08 Nov 92 04:34:06 GMT
  9. References: <Bx9D8A.3H0@iat.holonet.net> <1depklINNnpo@iskut.ucs.ubc.ca>
  10. Organization: Who is Organized ?
  11. Lines: 69
  12.  
  13. In article <1depklINNnpo@iskut.ucs.ubc.ca> ochealth@unixg.ubc.ca (ochealth) writes:
  14. >In article <Bx9D8A.3H0@iat.holonet.net> brianw@iat.holonet.net (Brian Walsh) writes:
  15. >:In message <2af8cafe.2066comp.sys.hp48@hpcvbbs.cv.hp.com> Joe Horn writes:
  16. >: 
  17. >:> (5)  Write a program that takes as input an integer 1 through 26, and
  18. >:>      creates that many (and no more) *local* variables 'a', 'b', 'c',
  19. >:>      etc., and then HALTs, leaving the local variables active.  Their
  20. >:>      contents do not matter.  Example: an input of 5 would create 'a',
  21. >:>      'b', 'c', 'd', and 'e', and nothing else.
  22. >: 
  23. >:Here are two solutions:
  24. >:%%HP: T(3)A(D)F(.);
  25. >:\<< 2 * 2 +
  26. >:"\-> 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"
  27. >:1 ROT SUB "\<<HALT" + STR\->
  28. >:\>>
  29. >:100.5 bytes
  30. >: 
  31. >:%%HP: T(3)A(D)F(.);
  32. >:\<< "\->" 1 ROT
  33. >:  FOR i " " + i 96 + CHR +
  34. >:  NEXT "\<<HALT" + STR\->
  35. >:\>>
  36. >:76.5 bytes
  37. >: 
  38. >:Both use the technique of building a program as a string and then using 
  39. >:STR-> to evaluate the program.  The second is quite small but takes more
  40. >:execution time.
  41. >
  42. >But the challenge said the program had to take a single integer as input,
  43. >and these programs assume that there are enough arguments on the stack.
  44. >At least that's how I read the challenge.
  45.  
  46. My 1st attemp was:
  47.  
  48. %%HP: T(3)A(D)F(.);
  49. \<<
  50.   "\->" SWAP
  51.   DO
  52.     SWAP " " +
  53.     OVER "`" NUM + CHR +
  54.   UNTIL
  55.     OVER 1 - DUP NOT
  56.   END
  57.   DROP
  58.   "\<<HALT" + STR\->
  59. \>>
  60. 85.5 bytes
  61.  
  62. But Brians modified 2nd solution is 6 bytes shorter:
  63.  
  64. %%HP: T(3)A(D)F(.);
  65. \<<
  66.   "\->" 1 ROT
  67.   FOR i
  68.       " " +
  69.       i "`" NUM SWAP OVER + CHR +
  70.   NEXT
  71.   "\<<HALT" + STR\->
  72. \>>
  73. 79.5 bytes
  74.  
  75. Bye,
  76.     8-Detlef
  77. --
  78. +------------------------------------+--------------------------------------+
  79. |`What a depressingly stupid machine'|             Detlef Mueller           |
  80. | -- Marvin                          |          detlef@dmhh.hanse.de        |
  81. +------------------------------------+--------------------------------------+
  82.