CHALLENGE. Write a shortest program in (a) UsrRPL program (b) SysRPL
whose input is a whole number n in Level2 and a DATE real in Level1, and
whose output is the correct date n years later as explained above.
CONDITIONS: The program should be independent on the date flag -42. Only
supported pointers and named rompointers are allowed. The input DATE can
be any real accepted by ->DATE. The output must be correct as long as <<
DATE n 365. * DATE+ >> does not error. Argument checking is not
required. The number in Level2 is a positive real with fractional part
0. TIME is not considered in the challenge.
- Wolfgang
ftp://ftp.math.fu-berlin.de/pub/usr/raut/HP49/time/Timeman/Timeman.htm
<< DUP DUP nDays 29 == SWAP 1 DATE+ nDays 31 == AND -> test
// We just tested if we were a Feb 29th
<< test {1 DATE+} IFT
//If it's the case, we work with March 1st for calculation
DUP 3 ROLL 1 SWAP FOR i i 4 MOD
// Every 4 years is expected as a leap year
0 == {366} {365} IFTE DATE+ NEXT SWAP 2 PICK
//The next part corrects any missing/extra leap year that could have been
added
2 ->LIST IP EVAL -
// here we correct the Feb 29th back if it's a leap year, or leave it to
March 1st
1 - DATE+ DUP nDays 29 <> test NOT OR DATE+
>>
>>
I can't test it without said previous program though, nor say the size. I'll
rewrite that for sysRPL tomorrow, because 3am is too late to read through
the doc.
The problem is that a loop takes time for huge jumps (around 26 seconds for
a 1253 year jump test)
The loop is likely to be useless, I expect something like (with n on the
first level):
"DUP 4 / IP SWAP 365 * +" to make the same number of days added.
It should look like this:
<< DUP DUP nDays 29 == SWAP 1 DATE+ nDays 31 == AND ->test
// We just tested if we were a Feb 29th
<< test {1 DATE+} IFT
//If it's the case, we work with March 1st for calculation
DUP 3 ROLL DUP
// Every 4 years is expected as a leap year
4 / IP SWAP 365* + DATE+ SWAP 2 PICK
//The next part corrects any missing/extra leap year that could have been
added
2 ->LIST IP EVAL -
// here we correct the Feb 29th back if it's a leap year, or leave it to
March 1st
1 - DATE+ DUP nDays 29 <> test NOT OR DATE+
>>
>>
"Wolfgang Rautenberg" <ra...@math.fu-berlin.de> a écrit dans le message de
news:3EEF4C39...@math.fu-berlin.de...
If started from a 29th of February, 1, 2 or 3 years later means the 1st
of March, i.e., the same day as if you'd started from the 1st of March.
To simplify things, no return to a 29th of February is demanded also in
the general case. Thus, even 1000 years later deviates from a 29th of
February in at most one day. Call this the simple solution in contrast
to the "remember-solution" (return to a 29th of February if started on
that day). This will certainly cost a lot of extra bytes.
- Wolfgang
ftp://ftp.math.fu-berlin.de/pub/usr/raut/HP49/time/Timeman/Timeman.htm
> CHALLENGE. Write a shortest program in (a) UsrRPL program (b) SysRPL
> whose input is a whole number n in Level2 and a DATE real in Level1, and
> whose output is the correct date n years later as explained above.
How about
::
%0 DATE+DAYS
SWAP %-6 ALOG %+ %*
%0
ERRSET
DATE+DAYS
ERRTRAP
::
DROP
%100 %1/ %1+ %+
%5 %6 %* %1-
DATE+DAYS
;
;
It's possible to do the same in UserRPL, but the IFERR..THEN..END
construct, the program delimiters and the reals 1.01 and 29 take extra
space.
Bytes (compiled): 62.5
HP49 Checksum: #BDC8h
Greetings
Thomas
--
Thomas Rast <t.r...@freesurf.ch>
"There is no way to peace. Peace is the way!"
-- Gandhi
first (working) try, and I took the liberty of changing the input sequence...
(seemed more logical to me? cfr. date days DATE+, now date years YEARS+)
68.0 CCCAh
In : date n
Out: date + n years
\<<
6. ALOG / SWAP
DUPDUP -2. ALOG MOD 3.03 + DDAYS 3. SAME
UNROT PICK3 NEG DATE+ + SWAP DATE+
\>>
It works for negative input years as well.
I can get it one byte shorter using 303 MANT io 3.03 ... oh well.
Cheers, Werner
> ::
> %0 DATE+DAYS
> SWAP %-6 ALOG %+ %*
> %0
> ERRSET
> DATE+DAYS
> ERRTRAP
> ::
> DROP
> %100 %1/ %1+ %+
> %5 %6 %* %1-
> DATE+DAYS
> ;
> ;
*Don't* try this, it's flawed and might well cause crashs. Sorry for
posting too quickly!
- Thomas
--
Taking what was said into account, I came up with this:
::
DUP %100 %* %IP DUP % 2902 // I haven't found how to downsize that real
%= SWAP %23 %10 %* %1- %= OR IT
:: %1 DATE+DAYS ;
SWAP %-6 %ALOG %* %+
;
73 bytes, crc #421h on my hp48+mk
>
> - Wolfgang
> ftp://ftp.math.fu-berlin.de/pub/usr/raut/HP49/time/Timeman/Timeman.htm
second try:
@ 50.0 bytes
@ 1786h
\<<
6. ALOG / SWAP
DUP MANT IP 2. SAME
UNROT PICK3 NEG DATE+ + SWAP DATE+
\>>
The idea is that I don't have to test for Feb 29th specifically.
date - 1 day + n years + 1 day will work for all days, except Mar 1.
The test above will produce a 0. for Mar 1 and a 1. for Feb 20th till 29th,
whatever the date format is.
Cheers,
Werner
Hi Werner, your smart program translated into SysRPL would probably look
as follows:
:: %6 %ALOG %/ SWAPDUP %MANTISSA %IP %2
'EvalNoCK:_sup (the strange name for PTR 25F29 in CD&TR's extable)
xSAME
DUP4UNROLL %CHS DATE+DAYS %+ SWAP DATE+DAYS
;
Do you know the reason why it doesn't work if 'EvalNoCk_sup xSAME is
replaced by the more natural %= COERCEFLAG ???
Regards Wolfgang
Hi Wolfgang,
I did not understand the requiremet:
"as long as
<< DATE n 365. * DATE+ >> does not error"
Would you please expain, the needs.
Here is my 57,5 Byte-b-version-contribution:
::
%0 @ to make sure, that e.g. 28.02 or 2.28 is
accepted
DATE+DAYS @ in the right way
SWAP
%6
%ALOG
%/
2DUP
%+
%0
ERRSET
::
DATE+DAYS
ROTROT2DROP
;
ERRTRAP
::
SWAP
%1
DATE+DAYS
%+
;
;
@
> Hi Wolfgang,
> I did not understand the requiremet:
> "as long as
> << DATE n 365. * DATE+ >> does not error"
> Would you please expain, the needs.
Heiko, it is obvious that if you try to compute DATE plus 1 Million
years then the builtin date command will error. I simplified things in
not demanding from you this kind of error trapping.
IMHO it will be hard to beat Werner with his ingenious UsrRpl-program
for solving the problem. Werner did more as expected in 2 directions:
the program is correct also for negative year addings, and it returns to
a 29th of a february if it exist.
- Wolfgang
I tried something as simple as :: TRUE CORECEFLAG %1 %1 %+ ;
and it inputs 1 instead of 1 1, so I assume that entry also exits out of the
program.
On a side note,
::
%6 %ALOG %/ SWAPDUP %MANTISSA %IP %2
xSAME
DUP4UNROLL %CHS DATE+DAYS %+ SWAP DATE+DAYS
;
works fine on a hp48, and I don't see what 'EvalNoCK:_sup is doing here.
>
> Regards Wolfgang
Yes, but this seems to depend on the status of the Return stack.
> On a side note,
> ::
> %6 %ALOG %/ SWAPDUP %MANTISSA %IP %2
> xSAME
> DUP4UNROLL %CHS DATE+DAYS %+ SWAP DATE+DAYS
> ;
> works fine on a hp48, and I don't see what 'EvalNoCK:_sup is doing here.
The problem is that if an error occurs after xSAME (by DATE+DAYS, say)
you would get the misleading error message
"SAME error
blabla"
That is a main reason why UsrRPL commands should be avoided inside
SysRPL, or be forced to "forget their names" by EvalNoCK. Anyway,
'EvalNoCk:_sup is unsupported. Hence, my program is inadmissable for the
challenge. Here my work-around for Werner's idea in SysRPL:
:: %-6 %ALOG %* SWAPDUP %MANTISSA %CEIL %2 %MOD
DUP4UNROLL %CHS DATE+DAYS %+ SWAP DATE+DAYS
;
That is faster than Werners wonderful program, and only 40 bytes :-)
It is the program-part for the year-browser keys of the virtual
date-browser in the latest edition of Timeman, see
ftp://ftp.math.fu-berlin.de/pub/usr/raut/HP49/time/Timeman/Timeman.htm
Regards Wolfgang
Hi, Wolfgang!
I looked at the code and could still read ASM well enough to see that
COERCEFLAG does not return to the RPL LOOP as every well-behaved object
ought to, but instead passes control to SEMI (;).
So, writing
%MANTISSA %IP %2 %= :: COERCEFLAG ;
will work. Or
... %= ITE %1 %0
which will probably make you cringe less.
A solution that does not waste bytes:
%MANTISSA %CEIL %2 %MOD
er it's even 2.5 bytes less! - SysRPL version only
Moreover, I have rewritten the UserRPL program to be 48/49 compatible:
third try:
@ 50.0 bytes
@ 1CA6h (49)
\<<
6. ALOG /
OVER MANT IP 2. SAME
ROT OVER NEG DATE+ ROT + SWAP DATE+
\>>
And the SysRPL version would be something like:
40 bytes, 47E7h (49)
::
%6 %ALOG %/
SWAPDUP %MANTISSA %CEIL %2 %MOD
DUP4UNROLL %CHS DATE+DAYS %+ SWAP DATE+DAYS
;
Best Regards,
Werner
[r->] [OFF]
.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
Assuming my interpretation of the above requirements is correct, then
here are two solutions that should work. Each accepts a positive or
negative year argument in level 2 and a date argument in level 1.
User-rpl
Bytes : 48
Checksum : # 1A3h (48)
<< 1.012 DUP ROT
DDAYS SWAP ROT 6
ALOG / + SWAP DATE+ >>
System-rpl
Bytes : 35.5
Checksum : # 7595h (48)
::
% 1.012 DUPROT DDAYS SWAPROT
%6 %ALOG %/ %+SWAP DATE+DAYS
;
Jonathan
>Assuming my interpretation of the above requirements is correct, then
>here are two solutions that should work. Each accepts a positive or
>negative year argument in level 2 and a date argument in level 1.
>
>User-rpl
>Bytes : 48
>Checksum : # 1A3h (48)
>
><< 1.012 DUP ROT
> DDAYS SWAP ROT 6
> ALOG / + SWAP DATE+ >>
>
>
>System-rpl
>Bytes : 35.5
>Checksum : # 7595h (48)
>
>::
> % 1.012 DUPROT DDAYS SWAPROT
> %6 %ALOG %/ %+SWAP DATE+DAYS
>;
Crap. Posted too soon. Dates other than february 29 are off by 1.
Nth note to self: think before posting....
Jonathan
>On Sat, 21 Jun 2003 18:56:19 -0500, Jonathan Busby
><temp...@thisIsInvalid.net> wrote:
>
>
>>Assuming my interpretation of the above requirements is correct, then
>>here are two solutions that should work. Each accepts a positive or
>>negative year argument in level 2 and a date argument in level 1.
Here's a "conventional" sys-rpl solution. Still falls 5 bytes short of
Werner's though. ( just 2 commands ;)
::
SWAP %6 %ALOG %/ SWAP2DUP %+
DUP
ERRSET
DDAYS
ERRTRAP
%-1
DUP4UNROLL DATE+DAYS %+SWAP
%CHS DATE+DAYS
;
Jonathan
Thanks to all participants. The winner of this challenge in both
sections, UsrRPL and SysRPL, is Werner Huysegoms with his programs
\<< 6. ALOG / OVER MANT IP 2. SAME ROT OVER
NEG DATE+ ROT + SWAP DATE+ \>> (50 bytes)
:: %6 %ALOG %/ SWAPDUP %MANTISSA %CEIL %2 %MOD
DUP4UNROLL %CHS DATE+DAYS %+ SWAP DATE+DAYS ; (40 bytes)
The small UsrRPL program belongs to the best ones I have ever seen.
The "Ceil"-trick in the second program was proposed by Werner and myself
independently.
It can be replaced by the unsupported but stable HP49-PTR 3CCB4 which is
the already mentioned :: EQUAL COERCEFLAG ; This pointer is very useful
and should be included in TR's extable2. Any good name for it?
- Wolfgang
I just used TR's Extable Tools library to add the pointer "SAME" but
forgot to write "SAME_" as it should perhaps be. I thought that would be
done by ->ETAB automatically :-)
Some remarks to Extable Tools (for the HP49, not for a PC!).
1. It should perhaps do the necessary temporary UNDO_OFF by itself, by
just warning at the very end that Last Stack may be disabled.
2. It should not check for the name extable but for a name beginning
with extable. In this way extable could be given another name,
extable2, say.
3. The command ->ETAB should accept a 3rd argument, the name the user
wants to give his own updated extable, to distinguish it from the
various public versions.
4. In tabtool.txt should not be written "Make a short one-line string"
if in reality this has to be a 2-line string, with a single blank
in the second line.
- Wolfgang
I just used TR's Extable Tools library to add the pointer "SAME" but
forgot to write "SAME_" as it should perhaps be. I thought that would be
done by ->ETAB automatically :-)
Some remarks to Extable Tools (for the HP49, not for a PC!).
1. It should perhaps do the necessary temporary UNDO_OFF by itself, by
just warning at the very end that Last Stack may be disabled.
2. It should not check for the name extable but for a name beginning
with extable. In this way extable could be given another name,
extable2, say.
3. The command ->ETAB should accept a 3rd argument, the name the user
wants to give his own updated extable, to distinguish it from the
various public versions. Better if ETAB-> would not check for the
name at all.
4. In tabtool.txt "Make a short one-line string" should be completed
by "with a newline-character at the very end, e.g. as follows:"
- Wolfgang
I just used TR's Extable Tools library to add the pointer "SAME" but
forgot to write "SAME_" as it should perhaps be. I thought that would be
done by ->ETAB automatically :-)
Some remarks to Extable Tools (for the HP49, not for a PC!).
1. It should perhaps do the necessary temporary UNDO_OFF by itself, by
just warning at the very end that Last Stack may be disabled.
2. It should not check for the name extable but for a name beginning
with extable. IMHO it would suffice if it checks for LibID 258. In this
way extable could be given another name, extable2, say.
3. The command ->ETAB should accept a 2nd argument, the name the user
wants to give his individually updated extable, to distinguish it from
the various public versions.
A small optimization brings the sys-rpl version down to 37.5 bytes :
:: %6 %ALOG %/ SWAPDUP %MANTISSA %CEIL %2 %MOD
DUP4UNROLL %CHS DATE+DAYS %+SWAP DATE+DAYS ;
Heh, I just realized that the second line is almost identical to the
end of my (working) sys-rpl solution (which was developed
independently). I guess that's what happens when there's really only
one optimum way to do it. :)
Jonathan
>Here's a "conventional" sys-rpl solution. Still falls 5 bytes short of
>Werner's though. ( just 2 commands ;)
Actually, if you remove the initial SWAP ( arguments reversed ), it's
only 2.5 bytes. (if anyone cares)
Jonathan
WR> I just used TR's Extable Tools library to add the pointer "SAME" but
WR> forgot to write "SAME_" as it should perhaps be. I thought that would be
WR> done by ->ETAB automatically :-)
No, it is not the extable tools which are doing this, because they
cannot know which entries are stable and which not. Appending "_"
happens when I export from the database, because the DB knows which
entries are supported and which not. In the database, entries are
called "SAME" - only for extable do we add the "_". So indeed, you
should have added the "_" yourself.
WR> 4. In tabtool.txt "Make a short one-line string" should be completed
WR> by "with a newline-character at the very end, e.g. as follows:"
Thomas, I think also the "*" as a replacement for the space separator
is currently undocumented.
- Carsten
PS - ADDITIONAL REMARK. I repeat that Werner's UsrRPL program is the
most beautyful one I've ever seen. I'm sad that this minichallenge which
(in contrast to similar ones) has some obvious application in practice,
didn't find much resonance by people in this NG who program in UsrRPL.
It turns out that the so-called gurus which normally don't care much on
UsrRPL are still winning nearly all UsrRPL-competitions. Why is this
so?
> [..]
> It's the first time I saw this
> %+SWAP in a SysRPL program :-)
>
The entry itself is not new.
It's even in the HP-48SX....
Raymond
> The entry itself is not new.
I know, it's well-document. But I never met a place in the HP48-ROM
where it is used. Do you have such an example (from the ROM)?
- Wolfgang
"Wolfgang Rautenberg" <ra...@math.fu-berlin.de> schrieb im Newsbeitrag
news:3EFC16AD...@math.fu-berlin.de...
Yes, of course.
Here are locations where %+SWAP is used:
C%R+C
C%C+C
DOARC# (which is called by xARC)
Ok, it's not many, but however;-)
Raymond
Two reasons:
a) It probably helps to know userRPL really well before learning sysRPL
b) Those who have time to learn sysRPL also have time to enter the
mini-challenges. ;-)
Regards,
--
Bruce Horrocks
Surrey
England
<firstname>@<surname>.plus.com -- fix the obvious for email