From: Han on
> It would *seem* that all integers raised to the 4th power contain at
> least one digit less than 5.  For example, 26 to the 4th power is
> 456976, which contains a 4.  However, there does exist a positive
> integer X such that X^4 contains no digits less than 5.
>

I am starting to believe that it is possible to solve this problem
completely using elementary number theory. Let's see what a few more
days of proofs produce =)
From: Brian Walsh on
On Mar 23, 8:23 pm, Joe Horn <joeh...(a)holyjoe.net> wrote:
> > > Tumbolia, the place where hiccups go when they go away.  ;-)
>
> > Uh, as I recall, one of the GEB dialogs refers to Tumbolia as the
> > destination of lost / mismatched socks.  Those two ingredients lead to
> > a disquieting mental image...
>
> That's why getting a good sock in the mouth makes hiccups go away.
>
> -Joe-

Ahmghnathkuhfthtwhn
(removes sock from mouth)
I'm gonna sock you for that one. *hic*

Brian
From: stephen on
Hi everyone,

Can I just say that I love this?

I just bought my first HP calculator a few months ago. Not used an
RPN
calculator before, though did do Forth programming earlier in my
career
so very familiar with the concept.

I bought the HP48Gii which I know a lot of you will probably have a
problem with, but I couldn't really afford or justify an HP50g, though
I
might buy one one day if I really use this one a lot.
It's also the duff old HP48Gii with only 3xAAA and no USB port. Read
several things saying this one had been superseded, but even HP's
website now lists the model I have as current and doesn't mention a
USB
version.

I happened upon this group while using google to search for the
solution
to a problem I had. What luck!

Anyway, I managed to solve the MC, though my version of the program
took
just over an hour to run! :-D

I really wasn't trying hard to optimise it, I just wanted to produce
something and to try out some of the stuff I've learned since I bought
the calculator.

I also wanted to break the program down into manageable chunks so I
used
several routines to achieve what I wanted to do. I know this will
probably affect how long it took significantly, but I'm really just
doing this for fun and to learn, not to compete! :-)

Here's what I did, if anyone is interested. Don't rip it all apart,
but
friendly comments very welcome!

First I figured that I would want to work out how to check if one of
these numbers matches the criterion of having no digits less than 5,
and
to do this I would want to treat each digit separately, so I thought
it
would be nice to separate the number out into a list of digits.

My first routine takes a number from the stack, and returns to the
stack
the last digit along with the rest of the number ready for processing:

GetD:
<< DUP 10 IDIV2 DROP SWAP 10 MOD >>
e.g. 123 GetD returns 12 3

The next routine takes a list and a number, and returns the same list
with the last digit of the number added, plus the rest of the number
for
processing:

AddD
<< GetD ROT SWAP + SWAP >>
e.g. { 1 } 23 returns {1, 2} 3

The next routine takes a number from the stack, and returns a list
containing the digits of that number on the stack

DList:
<< { } SWAP
WHILE
DUP 0 <> # ok, so really it's the proper not equals symbol!
REPEAT
AddD
END DROP
>>
e.g. 12345 returns {1, 2, 3, 4, 5}

The next routine tests if a number has any digits less than 5. I was
thinking about how to do a foreach type thing and how I could write
something to run a given routine on each element of a list and either
AND or OR the results together. Then I remembered that I can do an
operation on a list and it does it on each element.
I really like this!

DigL5:
<< DList 5 >= #LIST NOT >> # #LIST's # is really pi for product of
#list.

So then I did my main routine. I skipped doing 1, since I found that
#LIST fails with one element. Seems kind of daft to me, surely it
should just return that element, but never mind.
<< 2 -> X
<< WHILE X 4 ^ DigL5
REPEAT X 1 + DUP 'X' STO 4 DISP
END X
>>
>>
This returns the answer as Jim revealed above.

The DISP stuff was just added so I can tell it is really doing
something
because it takes so long!

I'll probably spend some time looking at how I can optimise it now.
One obvious optimisation, now I've structured it so I can understand
what's
going on would be to get rid of some of these abstraction layers.
Then
I'll be able to, for example, abort checking a number when I first see
a digit
<5 rather than having to extract all the digits before I process any
of
them.

Thanks very much Joe. That was a very entertaining diversion, and
it's
really helping me to get acquainted with this great machine.

Hope I haven't bored everyone too rigid with all the detail!

Stephen Blythe


From: Han on
I think your program is great for someone who just recently started
programming in RPL. Over time you will learn how to optimize your
program as you discover how certain objects are handled by the
calculator. Also, the more mathematics you know (about the problem),
the more you can optimize your program.

For example, is it necessary to actually create a list of all the
digits prior to checking each digit? Perhaps within your subroutine
that extracts each digit, you may as well test the digit too... and
stop as soon as you find a "small" digit. You will eventually see that
oftentimes, there is a lot of "checking" that is extraneous. Regarding
what I just wrote, if you notice that the first digit is already
"small", then is there any reason to check the remaining digits?

Other things to try: consider turning a number into a character
string, and search the digits that way (see the SUB command). You may
find that extracting characters from a string requires less of the CPU
than using integer division. Moreover, the effect you want can also be
achieved with HEAD and TAIL (these are commands).

Anyway, as Joe said from the outset -- the key is to have fun. Judging
from your post, I think you've done just that! Good luck in your
pursuit of understanding RPN, RPL, and the HP series of calculators!

Han
From: Dave Hayden on
On Mar 26, 7:05 pm, stephen <s...(a)urwick.co.uk> wrote:
> Hi everyone,

> I bought the HP48Gii which I know a lot of you will probably have a
> problem with, but I couldn't really afford or justify an HP50g, though
> I
> might buy one one day if I really use this one a lot.
> It's also the duff old HP48Gii with only 3xAAA and no USB port.  Read
> several things saying this one had been superseded, but even HP's
> website now lists the model I have as current and doesn't mention a
> USB
> version.

Personally, I think the 48gII is an excellent value. Check out
HPUserEdit or Debug4x for programming. It's much easier to develop
programs on a PC and then download them to the calculator when you're
done.


> Anyway, I managed to solve the MC, though my version of the program
> took
> just over an hour to run! :-D

I think your post is an excellent example of how to break a program
into manageable parts, so even though it might not be super fast, it's
a great tutorial. Thanks for posting it.

Dave