From: ochealth@unixg.ubc.ca (ochealth)
Newsgroups: comp.sys.hp48
Subject: Re: Cliff Stern's Little Challenges
Date: 5 Nov 1992 20:05:46 GMT
Organization: University of British Columbia, Vancouver, B.C., Canada
NNTP-Posting-Host: unixg.ubc.ca

In article <2af8cafe.2066comp.sys.hp48@hpcvbbs.cv.hp.com> akcs.joehorn@hpcvbbs.cv.hp.com (Joseph K. Horn) writes:
:*** RECREATIONAL PROGRAMMING DEPARTMENT ***
:
:All you old-timers: remember Cliff Stern?  He was very active in the
:PPC heydays, especially in the field of HP-41 "m-code" programming.
:
:Well, he has an HP 48 now, but no computer, hence no access to the net
:or to System RPL or ML.  But he gets a kick out of optimizing User RPL
:programs, and we often swap fun challenges over the phone.
:
:You'll enjoy Cliff Stern's latest challenges.  Use 100% normal User
:RPL, with no SYSEVAL's or monkey business!  These are really tests of
:your knowledge of HP-documented User RPL, not of bizarre undocumented
:HP 48 anomalies.  Of course, assume default mode settings, etc.
:
:----
:
:(1a) Write a program that takes as input a real number on level 1, and
:     then drops it if it's a zero, or leaves it alone if it's not zero.
:
:(1b) Using IF-THEN-END, do the same program in 20 bytes (including the
:     << >> program delimiters; use the BYTES command to check).
Try it before you read on

<< IF THEN LASTARG END >>

- I think LASTARG is cheating though

:
:(1c) Now do it in 15 bytes.  (Hint: don't use IF-THEN-END).
:

<< DUP IFT >>
:----
:
:(2a) Write a program that takes as input a list of two or more reals
:     on level 1, and replaces it with the sum of its elements.
:
:(2b) Now do the same program in 25 bytes (including << >> as always).

<< OBJ-> ->ARRY DUP 1 CON DOT >>

:
:(2c) If we can assume that all the elements are positive, do the same
:     program in 17.5 bytes.
:

<< OBJ-> ->ARRY CNRM >>

:----
:
:(3a) Assume that there is at least one object on the stack.  Write a
:     program that clears the stack of everything *except* for the
:     object in level 1, which is left alone.  (Can be thought of as 1
:     KEEP).  Remember: no SYSEVALs or library function calls!
:


<< -> x << CLEAR x >> >>

:(3b) Now do it in 17.5 bytes.


<< DROP CLEAR LASTARG >>

still think LASTARG is cheating though..
:
:----
:
:(4)  Place WHILE UNTIL END on level 1, just like that (without any <<
:     >> program or { } list delimiters around it).  Remember: no
:     SYSEVALs or library function calls!


Without any quotes around it?? like " or '. I'm suspicious. The closest
I can come is 
<< :WHILE UNTIL END:0 >> or something like that.

:----
:
:(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.
:


<< DUP {} + 0 CON OBJ-> EVAL ->LIST
  "<<-> " 97 DUP 5 ROLL + 1 - 
  FOR i i CHR + " " + NEXT
  "<<HALT" + OBJ-> + EVAL 
>>

113.5 bytes


Recursion can improve this slightly:

<< DUP IF 1 == THEN -> a << HALT >>
   ELSE 1 - DUP 97 + CHR  "<<0-> " SWAP + "<<X" + OBJ-> EVAL
   END
>>
103.5

store in X
:----
:
:Problems 1 through 4 are non-obvious but are not difficult.
:Problem 5 is more difficult but very possible.  My first attempt
:yielded a 115.5-byte solution; I'm sure there's a shorter way.
:
:Have fun!  -Joe Horn-
:


-- 
______________________________________________________________________________
jpm: ochealth@unixg.ubc.ca         
                            Happily using OS/2 2.0 because MS Windows isNT ___
                                                      Insert VapourFeature ^^^
Newsgroups: comp.sys.hp48