Post Reply 
HP 49G Programming Challenge: OEIS A014261, Integers with exclusively Odd Digits
08-30-2017, 01:39 PM
Post: #23
RE: HP 49G Programming Challenge: OEIS A014261, Integers with exclusively Odd Digits
(08-30-2017 12:20 PM)Werner Wrote:  An iterative version (even if I favour the recursive one)
For the 49 and up, replace / IP by IQUOT

Code:
\<<
    0 SWAP
    DO
      1 - DUP 5 MOD DUP + 1 +
      ROT 1 + ROT 5 / IP
    UNTIL DUP NOT
    END
    1 ROT START 10 * + NEXT
\>>

Cheers, Werner

And here are Werner's timings on the 50g (don't have a 49g to give comparable values). In both cases I replaced / IP with IQUOT.
50000 runs with 50 as argument in 11.01 seconds on newRPL.
100 runs with 50 as argument in 26.66 seconds on 50g stock firmware.

I thought this would've been a lot faster without using STO (especially on stock firmware, probably negligible difference on newRPL), but is not the case, perhaps doing MOD and IQUOT together in the main loop is hurting performance, maybe using IDIV2:

Code:
\<<
    0 SWAP
    DO
      1 - 5 IDIV2 DUP + 1 +
      ROT 1 + ROT 
    UNTIL DUP NOT
    END
    1 ROT START 10 * + NEXT
\>>

It did improve to 10.13 sec. (from 11.01sec) on newRPL, and down to 23.33 sec. on stock firmware in exact mode, but slows down to 30.0 sec in approx mode (recompiled with reals, but why? perhaps IDIV2 needs to convert the reals back to integer?).

I think for the 49g, and as long as it runs in exact mode, this is likely to be the winner entry (all credit to Werner of course), my entry clocked 24.2sec under the same conditions. Close, but slower.
The weird part is my algorithm using IQUOT went even faster using reals in approx. mode, I can't understand why this algorithm (quite similar, actually) slows down with reals. So far it's a mystery to me.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 49G Programming Challenge: OEIS A014261, Integers with exclusively Odd Digits - Claudio L. - 08-30-2017 01:39 PM



User(s) browsing this thread: 1 Guest(s)