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

  1. Path: sparky!uunet!gumby!destroyer!cs.ubc.ca!unixg.ubc.ca!ochealth
  2. From: ochealth@unixg.ubc.ca (ochealth)
  3. Newsgroups: comp.sys.hp48
  4. Subject: Re: Cliff Stern's Little Challenges
  5. Date: 5 Nov 1992 20:05:46 GMT
  6. Organization: University of British Columbia, Vancouver, B.C., Canada
  7. Lines: 121
  8. Message-ID: <1dbuqqINN9kr@iskut.ucs.ubc.ca>
  9. References: <2af8cafe.2066comp.sys.hp48@hpcvbbs.cv.hp.com>
  10. NNTP-Posting-Host: unixg.ubc.ca
  11.  
  12. In article <2af8cafe.2066comp.sys.hp48@hpcvbbs.cv.hp.com> akcs.joehorn@hpcvbbs.cv.hp.com (Joseph K. Horn) writes:
  13. :*** RECREATIONAL PROGRAMMING DEPARTMENT ***
  14. :
  15. :All you old-timers: remember Cliff Stern?  He was very active in the
  16. :PPC heydays, especially in the field of HP-41 "m-code" programming.
  17. :
  18. :Well, he has an HP 48 now, but no computer, hence no access to the net
  19. :or to System RPL or ML.  But he gets a kick out of optimizing User RPL
  20. :programs, and we often swap fun challenges over the phone.
  21. :
  22. :You'll enjoy Cliff Stern's latest challenges.  Use 100% normal User
  23. :RPL, with no SYSEVAL's or monkey business!  These are really tests of
  24. :your knowledge of HP-documented User RPL, not of bizarre undocumented
  25. :HP 48 anomalies.  Of course, assume default mode settings, etc.
  26. :
  27. :----
  28. :
  29. :(1a) Write a program that takes as input a real number on level 1, and
  30. :     then drops it if it's a zero, or leaves it alone if it's not zero.
  31. :
  32. :(1b) Using IF-THEN-END, do the same program in 20 bytes (including the
  33. :     << >> program delimiters; use the BYTES command to check).
  34. Try it before you read on
  35.  
  36. << IF THEN LASTARG END >>
  37.  
  38. - I think LASTARG is cheating though
  39.  
  40. :
  41. :(1c) Now do it in 15 bytes.  (Hint: don't use IF-THEN-END).
  42. :
  43.  
  44. << DUP IFT >>
  45. :----
  46. :
  47. :(2a) Write a program that takes as input a list of two or more reals
  48. :     on level 1, and replaces it with the sum of its elements.
  49. :
  50. :(2b) Now do the same program in 25 bytes (including << >> as always).
  51.  
  52. << OBJ-> ->ARRY DUP 1 CON DOT >>
  53.  
  54. :
  55. :(2c) If we can assume that all the elements are positive, do the same
  56. :     program in 17.5 bytes.
  57. :
  58.  
  59. << OBJ-> ->ARRY CNRM >>
  60.  
  61. :----
  62. :
  63. :(3a) Assume that there is at least one object on the stack.  Write a
  64. :     program that clears the stack of everything *except* for the
  65. :     object in level 1, which is left alone.  (Can be thought of as 1
  66. :     KEEP).  Remember: no SYSEVALs or library function calls!
  67. :
  68.  
  69.  
  70. << -> x << CLEAR x >> >>
  71.  
  72. :(3b) Now do it in 17.5 bytes.
  73.  
  74.  
  75. << DROP CLEAR LASTARG >>
  76.  
  77. still think LASTARG is cheating though..
  78. :
  79. :----
  80. :
  81. :(4)  Place WHILE UNTIL END on level 1, just like that (without any <<
  82. :     >> program or { } list delimiters around it).  Remember: no
  83. :     SYSEVALs or library function calls!
  84.  
  85.  
  86. Without any quotes around it?? like " or '. I'm suspicious. The closest
  87. I can come is 
  88. << :WHILE UNTIL END:0 >> or something like that.
  89.  
  90. :----
  91. :
  92. :(5)  Write a program that takes as input an integer 1 through 26, and
  93. :     creates that many (and no more) *local* variables 'a', 'b', 'c',
  94. :     etc., and then HALTs, leaving the local variables active.  Their
  95. :     contents do not matter.  Example: an input of 5 would create 'a',
  96. :     'b', 'c', 'd', and 'e', and nothing else.
  97. :
  98.  
  99.  
  100. << DUP {} + 0 CON OBJ-> EVAL ->LIST
  101.   "<<-> " 97 DUP 5 ROLL + 1 - 
  102.   FOR i i CHR + " " + NEXT
  103.   "<<HALT" + OBJ-> + EVAL 
  104. >>
  105.  
  106. 113.5 bytes
  107.  
  108.  
  109. Recursion can improve this slightly:
  110.  
  111. << DUP IF 1 == THEN -> a << HALT >>
  112.    ELSE 1 - DUP 97 + CHR  "<<0-> " SWAP + "<<X" + OBJ-> EVAL
  113.    END
  114. >>
  115. 103.5
  116.  
  117. store in X
  118. :----
  119. :
  120. :Problems 1 through 4 are non-obvious but are not difficult.
  121. :Problem 5 is more difficult but very possible.  My first attempt
  122. :yielded a 115.5-byte solution; I'm sure there's a shorter way.
  123. :
  124. :Have fun!  -Joe Horn-
  125. :
  126.  
  127.  
  128. -- 
  129. ______________________________________________________________________________
  130. jpm: ochealth@unixg.ubc.ca         
  131.                             Happily using OS/2 2.0 because MS Windows isNT ___
  132.                                                       Insert VapourFeature ^^^
  133.