It's been forever since the last "mini-challenge". So here's a really
easy one that everybody can try.
Write the smallest RPL program that gives all the *pairs* of factors
of an integer.
Example:
Input: 12
Output: { { 1 12 } { 2 6 } { 3 4 } }
Another example:
Input: 25
Output: { { 1 25 } { 5 5 } }
Full description: Write an RPL program that inputs any integer and
outputs every possible *pair* of integer factors. The output is a
list of lists, with each sublist containing a pair of factors, as in
the example above.
Output must be complete. The order of the factors in each pair, and
the order of the pairs, does not matter. Repeats are not allowed.
The usual mini-challenge rules apply. Only native User-RPL is
allowed. Embedding code into a string then executing it via OBJ-> or
STR-> is a Bad Thing. And so on.
The SMALLEST program (in bytes) wins. Prize: eternal fame in the
comp.sys.hp48 archives.
As a first effort:
\<< DIVIS DUP REVLIST 2 \->LIST AXL TRN AXL 1 OVER SIZE 2 / CEIL SUB \>>
# 688Fh
59.5 bytes.
Virgil, great job - I think you won. My program is over 165 bytes. Is
there actually any room left for improvement?
Thanks for showing teaching me a thing or two about RPL.
And to anyone: more mini-challenges please.
Cheers.
I found a few alternates in the 60 to 80 byte range, but have not been
able to improve on my first effort. Very unusual to be able to do so
well on my first try. But as I have been doing some programs that used
pretty much all the commands that I used in that first effort, they were
all in my mind when I began to work on it.
>
> Thanks for showing teaching me a thing or two about RPL.
I still learn from lots rom others, Joe Horn not least among them.
It's seems a shame that the first mini challenge to come along in such
a long time is over before it's started. The one submitted solution is
so incredibly elegant that's it's improbable (I hate the word
impossible) to beat. Fun challenge though and fantastic solution. I
learn more about my 50g all the time. :D
You can shorten this one by 2.5 bytes if you use a quirk of the SUB
function. It will do the CEIL for you (at least here on my Emu48 HP
50g), so you can take that out, leaving the slightly shorter:
\<< DIVIS DUP REVLIST 2 \->LIST AXL TRN AXL 1 OVER SIZE 2 / SUB \>>
# C3B5h
57.0 bytes
Credit still goes to Virgil on this one ;-)
-Dave
I knew that somebody could improve on it, somehow.
Thanks for the tip.
Actually I knew that trick way back when I was new with a 48, way before
the 49's and 50's, but forgot it over time.
Kind of wish I had held off posting for a few days, just to see what
others could have come up with.
This is the first custom program I'm entering into my shiny new HP50g,
but I'm getting a small syntax error. I'd be grateful for some
clarification please...
Looks like my mistake is in this section "2 \->LIST". I'm getting
either a syntax error or AXL error, depending on the various
characters I try in order to get that right.
To me (complete novice at this) it looks like " 2 space backslash
hyphen (minus) rightchevron L I S T " etc. I've tried with hyphens and
underscores and the little right pointing arrow on right shift 0 key
but it's still not right. Anyone help please?
Just to describe properly, program is entered and stored fine. If I
put, say, 30 on the stack and run, then I see two horizontal lists
showing my pairs of factors, but then program stops with error
message !AXL Error: Bad argument type '\->LIST'
Thanks if you can point out my silly mistake
> syntax error at 2 \->LIST
"\->" means the single "right-arrow" character
(right-shift zero on the calculator keyboard)
Quite a few such 8-bit characters are used in UserRPL programming,
and since these characters do not represent the same symbol
in everyone's computer, there is a "backslash" scheme
for representing these characters in "plainer" (7-bit) text,
for postings, for email, or for external "source" archives:
"Ascii \xx symbols"
http://groups.google.com/group/comp.sys.hp48/msg/52e9cc3ee2b369b8
A web page (by Joe Horn)
containing a larger, easy to read chart:
http://holyjoe.net/hp/tiotable.htm
The calculator itself is able to translate these symbols
between 8-bit internal characters and 7-bit "backslash sequences,"
but only while transferring text files from or to external sources,
or using additional calculator programs, such as:
"Ascii Import/Export for SD card and Emulator"
http://groups.google.com/group/comp.sys.hp48/msg/4e7ed90b3cf11c42
[r->] [OFF]
> On Jul 30, 8:25�am, Virgil <Vir...@home.esc> wrote:
> >
> > \<< DIVIS DUP REVLIST 2 \->LIST AXL TRN AXL 1 OVER SIZE 2 / CEIL SUB \>>
>
> This is the first custom program I'm entering into my shiny new HP50g,
> but I'm getting a small syntax error. I'd be grateful for some
> clarification please...
>
> Looks like my mistake is in this section "2 \->LIST". I'm getting
> either a syntax error or AXL error, depending on the various
> characters I try in order to get that right.
The backslash "\" indicates that the following symbol or symbols
represent a character that is not representable in the standard newsnet
character set.
When entering the code into your calculator the sequence "\->"
represents a simple, and single, right-arrow character, and the whole
command should appear in the calculator program as ->LIST without any
backslash.
You might note that the same backslash shown in the \<< and \>> at the
ends of the program also should appear in the calculator without the
backslashs.
See if this doesn't clear things up.
> The backslash "\" indicates that the following symbol or symbols
> represent a character that is not representable in the standard newsnet
> character set.
>
> When entering the code into your calculator the sequence "\->"
> represents a simple, and single, right-arrow character, and the whole
> command should appear in the calculator program as ->LIST without any
> backslash.
Oohhh, you're a star! Not only did you write it, but now you're doing
the customer support too.
That fixed things up a treat, and it's now working perfectly. Thanks
very much.
You are most welcome.
> "\->" means the single "right-arrow" character
> (right-shift zero on the calculator keyboard)
> "Ascii \xx symbols"http://groups.google.com/group/comp.sys.hp48/msg/52e9cc3ee2b369b8
>
> A web page (by Joe Horn)
> containing a larger, easy to read chart:http://holyjoe.net/hp/tiotable.htm
That's very helpful info, and no doubt will be invaluable as I try and
get to grips with the 50g. Thanks very much.
My original one was 77 bytes, so hats off to Virgil. However, besides
not using CEIL, mine also replaced "AXL TRN AXL" with "TRAN". TRAN
can work directly with a list, so no need for the AXL's.
\<< DIVIS DUP REVLIST 2 \->LIST TRAN 1 OVER SIZE 2 / SUB \>>
# 5B30h
49.0 bytes
-wes
> On Aug 3, 8:42�pm, David Brigada <bri...@rpi.edu> wrote:
> > Virgil wrote:
> > > As a first effort:
> >
> > > \<< DIVIS DUP REVLIST 2 \->LIST AXL TRN AXL 1 OVER SIZE 2 / CEIL SUB \>>
> > > # 688Fh
> > > 59.5 bytes.
> >
> > You can shorten this one by 2.5 bytes if you use a quirk of the SUB
> > function. �It will do the CEIL for you (at least here on my Emu48 HP
> > 50g), so you can take that out, leaving the slightly shorter:
> >
> > \<< DIVIS DUP REVLIST 2 \->LIST AXL TRN AXL 1 OVER SIZE 2 / SUB \>>
> > # C3B5h
> > 57.0 bytes
CEIL and some other commands and functions needing integer arguments
round such half integers up even on the earliest hp48s.
> >
> > Credit still goes to Virgil on this one ;-)
> >
> > -Dave
>
> My original one was 77 bytes, so hats off to Virgil. However, besides
> not using CEIL, mine also replaced "AXL TRN AXL" with "TRAN". TRAN
> can work directly with a list, so no need for the AXL's.
>
So it does. But how did you discover it?
> > My original one was 77 bytes, so hats off to Virgil. However, besides
> > not using CEIL, mine also replaced "AXL TRN AXL" with "TRAN". TRAN
> > can work directly with a list, so no need for the AXL's.
>
> So it does. But how did you discover it?
Well, I had "AXL TRAN AXL" in my program and was looking to squeeze a
few more bytes out it. On a whim I decided to see if TRAN would work
on a list, and voila, it worked. Afterwords, I looked up the TRAN
command in all the documentation that I have and could not find a
single reference to using TRAN on a list. Perhaps this is the first!
Nosy shows that TRAN simply converts a list to/from a matrix.
(~xTRAN ROMPTR 314 45)
::
CK1&Dispatch
BINT4
FPTR 6 33B=^MATTRAN
BINT5
::
FPTR 6 17A=^LIST2MATRIX
FPTR 6 33B=^MATTRAN
FPTR 6 179=^MATRIX2LIST
;
;
-wes
> Well, I had "AXL TRAN AXL" in my program and was looking to squeeze a
> few more bytes out it. On a whim I decided to see if TRAN would work
> on a list, and voila, it worked. Afterwords, I looked up the TRAN
> command in all the documentation that I have and could not find a
> single reference to using TRAN on a list. Perhaps this is the first!
Make that the second reference.
A little googling reveals that on Feb 23, 2003, John Meyers wrote:
================================
Wow, another slight correction:
TRN (an old HP48 command) does not accept
a "list of lists" format for a matrix,
but TRAN does!
================================
http://groups.google.com/group/comp.sys.hp48/msg/d8b697485305fc32?hl=en
-wes
> \<< DIVIS DUP REVLIST 2 \->LIST TRAN 1 OVER SIZE 2 / SUB \>>
> # 5B30h
> 49.0 bytes
Dude, you *rock*! <bows deeply>
-Joe-
27 days until HHC 2009!
http://hhuc.us
Bowing to Dave that is.
My own program, weighing in at 77bytes, split up the list into 2 sub-
lists, reversed one of them, then stitched them back together. Dave's
program more efficiently reverses a copy of the whole list, stitches
these together, then SUBs them. Using one SUB instead of two saves
quite a bit.
I can't even take credit for the "TRAN with a list" idea, having been
scooped by John by 9 years. :-)
-wes