Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi all,
To brighten up your Tuesday morning, here's an HP-15C really, really small, "Quickie" Mini-Challenge:
Assume you've got two coordinate data points (x1,y1) and (x2,y2) preloaded into the stack exactly like this:
T: y2
Z: x2
Y: y1
X: x1
Try and write a routine (LBL ... RTN) which takes as input these coordinate
data points and returns as output the distance between them in X.
For the HP-15C, there's a solution in 8 program steps or
less (including LBL and RTN). See how much time does it take you to find (or even better) it ! :-)
Best regards from V.
Edited: 9 Dec 2003, 7:15 a.m.
Posts: 785
Threads: 13
Joined: Jan 2005
If you would SWAP one of your many HP-15C to something, I would be pleased to try with (spoiling hint) Complex operations...
[VPN] - still without a HP-15C
Posts: 1,755
Threads: 112
Joined: Jan 2005
VPN posted:
"If you would SWAP one of your many HP-15C to something, I would be pleased to try
No way. I already gave you a very good advice (IMHO) to get one. There's nothing more I can do for you in this regard, save giving you yet another well-meant advice: harassing everyone on this list to get an HP-15C (and other calculators) is not the way, methinks.
And by 'harassing' (not sure if this is the right word, no offence intended) I mean posting to this forum continual requests for all sort of trades, both explicitly and subtly. I think it would be far more proper and better forum netiquette to post them to the Classified section, don't you think ?
Best regards from V.
Posts: 48
Threads: 7
Joined: Jan 1970
LBL A
ROLL D
SWAP
ROLL U
-
ROLL D
-
ROLL U
R-P
RTN
Having Problems getting 8 steps!
Posts: 301
Threads: 28
Joined: Jan 2005
I *think* that it is:
LBL A 42.21.11
I 42 25
Rv 33
I 42 25
R^ 43 33
- 30
->P 43 1
RTN 43 32
Please correct me if it is wrong...
Best regards,
Nelson
Posts: 301
Threads: 28
Joined: Jan 2005
If my logic is correct, there is the 32S version:
LBL A
CMPLX-
x,y->angle,r
RTN
Even smaller....
Posts: 785
Threads: 13
Joined: Jan 2005
Me think you right: classified
BUT think about how pissed *YOU* would be without a single HP-15C, while everyone else seems to have more than enough and, instead of showing any Christmas spirit, the rich people just think that the poor beggers are harassing them...
[VPN] (tongue in cheek, because there is no cheese?)
Posts: 785
Threads: 13
Joined: Jan 2005
I *think* that it is:.....LBL A.....I.....Rv.....I.....R^
.....-.....->P.....RTN
Please correct me if it is wrong...Best regards,Nelson
If my logic is correct, there is the 32S version:
LBL A.....CMPLX-.....x,y->angle,r.....RTN
Even smaller
*******
Seems like a happy owner of a HP-32S(II)/33S(42S?) will not need the HP-15C after all!
[VPN]
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Nelson:
Your solution is correct, congratulations, but there's another *slightly* faster one, in the same number of steps.
I don't want to spoil the fun by giving you any hints but think a little if you're doing something that's not needed and can be avoided, thus saving a little time :-)
Best regards from V.
Posts: 301
Threads: 28
Joined: Jan 2005
Yes, I'm a happy owner of *one* of each: 15C, 32S, 42S among others.
I begin to collect them in this year (aug/2003), before that I have only my 42S since 1989 (bought new).
My HP-15C I get here in Brazil for about US$45, NIB and my 32S for about US$50. If you search the web, you can get your own 15C.
Good luck!
Nelson
Posts: 93
Threads: 15
Joined: Jan 1970
Like a virgin: (I just turned on my computer, launching on the Forum and dont see anithing else):
HP32SII version:
LBL D
CMPLX-
y,x->fi,r
RTN
CK=A11B 6 bytes
Csaba
Posts: 93
Threads: 15
Joined: Jan 1970
LBL A
CL summa
summa -
roll down
roll down
summa +
summa y
summa x
y,x->fi,r
RTN
CK=145A 15 bytes, 10 steps
Csaba
Posts: 1,755
Threads: 112
Joined: Jan 2005
Very good, Csaba ! :-)
Can you find an 8-step solution in the HP-15C ? Nelson has found a perfectly correct solution in that number of steps, which can be improved slightly to make it run a little faster. Can you find both, Nelson's solution and my original, slightly faster one ? Or even improve on them ? :-)
Best regards from V.
Posts: 93
Threads: 15
Joined: Jan 1970
Valentin: I'm so sorry, but I have got a designing work by tomorrow... (driving-gear..., the final 'cut' at University ;) )
But... I think with 'RCL summa+' that is will smaller...
Csaba
Posts: 301
Threads: 28
Joined: Jan 2005
I tested this on the 15C, and it shows the same result without using complex numbers:
(The only requirement is that the statistical registers must be cleared first with the 'Clear Sigma', this function cannot be in the program as it clears the stack!)
LBL A 42.21.11
Sigma- 43 49
Rv 33
Rv 33
Sigma+ 49
RCL Sigma 45 49
->P 43 1
RTN 43 32
Edited: 9 Dec 2003, 3:01 p.m.
Posts: 8
Threads: 2
Joined: Jan 1970
Posts: 182
Threads: 9
Joined: Jun 2013
The shortest I can think of is:
LBL A
I
RDN
I
RUP
-
ABS
CF 8
RTN
which is still 9 steps. Of course you could omit CF 8 and leave the calc in complex mode.
The inevitable HP-48SX version is, of course
<< R-C ROT ROT R-C - ABS >>
which is only 6 commands as there are no labels or returns.
Ironically, the 32Sii's limited complex functionality (as compared to the HP-15C) makes the solution for this particular problem shorter than on the 15C :-(
Cheers, Victor
Posts: 1,755
Threads: 112
Joined: Jan 2005
RMillan posted:
"ABS instead of ->P? "
Correct! That's the exact intended solution of the puzzle.
Conversion to polar form (->P) changes the complex stack like this:
X: (x, y) ->P X: (mod, arg)
where mod = sqrt(x^2+y^2) and arg = arctan(y/x). We're only interested in the "mod" part, which is mathematically equal to the distance between both given data points, but we're not interested in the "arg" part at all, so it would be nice if we would find some way to avoid computing it at all.
This can be done using the ABS function, which returns the "mod" part alone, changing the complex stack like this:
X: (x, y) ABS X: (mod, 0)
and so we get the distance we need but avoid computing the unneeded angle altogether, thus saving a little time. Thus, my original fast 8-step solution was this:
01 LBL A
02 I
03 Rdown
04 I
05 Rup
06 -
07 ABS
08 RTN
Congratulations for solving it, extensive to all of you who took interest in this mini-challenge. The idea was to show how the comprehensive HP-15C built-in function set can be used in non-obvious ways to achieve apparently unrelated computations. In this case, the use of complex functions allows a single "-" operation to perform (x2-x1) and (y2-y1) *simultaneously*, and then ABS computes the square root of the sum of their squares without computing the angle. This way you get done a lot of computation using just *two* steps, "-" and "ABS". Neat :-)
Best regards from V.
Posts: 234
Threads: 33
Joined: Jan 1970
Tested with P41CX on my Tungsten-E
001 LBL
002 ST - Z
003 RDN
004 ST - Z
005 RDN
006 R-P
007 RTN
Posts: 1,755
Threads: 112
Joined: Jan 2005
|