Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MC: All pairs of factors of an integer

14 views
Skip to first unread message

Joe Horn

unread,
Jul 30, 2009, 2:50:40 AM7/30/09
to
Mini-challenge for RPL enthusiasts
by Joe Horn

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.

-Joe-
http://holyjoe.net/hhc2009

Virgil

unread,
Jul 30, 2009, 3:25:22 AM7/30/09
to
In article
<d9455264-975c-4243...@v15g2000prn.googlegroups.com>,
Joe Horn <joe...@holyjoe.net> wrote:

As a first effort:

\<< DIVIS DUP REVLIST 2 \->LIST AXL TRN AXL 1 OVER SIZE 2 / CEIL SUB \>>
# 688Fh
59.5 bytes.

greenchile505

unread,
Aug 1, 2009, 6:22:03 PM8/1/09
to
On Jul 30, 12:25 am, Virgil <Vir...@home.esc> wrote:
> In article
> <d9455264-975c-4243-82ce-60bc7f924...@v15g2000prn.googlegroups.com>,

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.

Virgil

unread,
Aug 1, 2009, 8:30:50 PM8/1/09
to
In article
<a8689525-1fe3-4fbc...@c14g2000yqm.googlegroups.com>,
greenchile505 <greenc...@yahoo.com> wrote:

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.

Mike Bryant

unread,
Aug 3, 2009, 11:14:02 AM8/3/09
to
On Jul 29, 11:50 pm, Joe Horn <joeh...@holyjoe.net> wrote:
> Mini-challenge for RPL enthusiasts
> by Joe Horn


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

David Brigada

unread,
Aug 3, 2009, 1:42:25 PM8/3/09
to

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

Virgil

unread,
Aug 3, 2009, 6:39:14 PM8/3/09
to
In article <h577ii$6t0$1...@misc-cct.server.rpi.edu>,
David Brigada <bri...@rpi.edu> wrote:

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.

Grufff

unread,
Sep 5, 2009, 12:00:49 AM9/5/09
to
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.

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

John H Meyers

unread,
Sep 5, 2009, 1:37:32 AM9/5/09
to
On Fri, 04 Sep 2009 23:00:49 -0500:

> 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]

Virgil

unread,
Sep 5, 2009, 1:42:53 AM9/5/09
to
In article
<3589290f-b7f7-4246...@r39g2000yqm.googlegroups.com>,
Grufff <evans.me...@googlemail.com> wrote:

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

Grufff

unread,
Sep 5, 2009, 1:55:23 AM9/5/09
to
On Sep 5, 6:42 am, Virgil <Vir...@home.esc> wrote:

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

Virgil

unread,
Sep 5, 2009, 2:02:33 AM9/5/09
to
In article
<8c64f6c9-bcfb-48ce...@y36g2000yqh.googlegroups.com>,
Grufff <evans.me...@googlemail.com> wrote:

You are most welcome.

Grufff

unread,
Sep 5, 2009, 2:04:45 AM9/5/09
to
On Sep 5, 6:37 am, "John H Meyers" <jhmey...@nomail.invalid> wrote:
> On Fri, 04 Sep 2009 23:00:49 -0500:

> "\->" 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.

Wes

unread,
Sep 5, 2009, 5:31:22 AM9/5/09
to
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
>
> 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.

\<< DIVIS DUP REVLIST 2 \->LIST TRAN 1 OVER SIZE 2 / SUB \>>
# 5B30h
49.0 bytes

-wes

A Nony Mouse

unread,
Sep 5, 2009, 12:37:24 PM9/5/09
to
In article
<cf34db2b-95ea-44b0...@x38g2000yqb.googlegroups.com>,
Wes <wjlte...@yahoo.com> wrote:

> 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?

Wes

unread,
Sep 5, 2009, 1:12:08 PM9/5/09
to
On Sep 5, 7:37 pm, A Nony Mouse <T...@mouse.hole> wrote:

> > 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

Wes

unread,
Sep 5, 2009, 2:56:05 PM9/5/09
to
On Sep 5, 8:12 pm, Wes <wjltemp...@yahoo.com> wrote:

> 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

joehorn

unread,
Sep 6, 2009, 3:21:13 AM9/6/09
to
Wes wrote:

> \<< 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

Wes

unread,
Sep 6, 2009, 7:44:46 AM9/6/09
to
On Sep 6, 10:21 am, joehorn <joeh...@holyjoe.net> wrote:
> Wes wrote:
> > \<< DIVIS DUP REVLIST 2 \->LIST TRAN 1 OVER SIZE 2 / SUB \>>
> > # 5B30h
> > 49.0 bytes
>
> Dude, you *rock*!  <bows deeply>
>
> -Joe-

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

0 new messages