Post Reply 
HP 49G Programming Challenge: OEIS A014261, Integers with exclusively Odd Digits
08-31-2017, 12:49 PM
Post: #28
RE: HP 49G Programming Challenge: OEIS A014261, Integers with exclusively Odd Digits
(08-29-2017 04:02 PM)Didier Lachieze Wrote:  My RPL is a bit rusty, so instead here is an HP Prime program:

Code:
EXPORT IntOdd(N)  
BEGIN  
    10*IFTE(N<=5,0,IntOdd(IP((N-1)/5)))+2*((N-1) MOD 5)+1;
END;

IntOdd(50) returns 179 in 0.5ms on my Prime.

This is brilliant work. I've done some programming in many languages, but I've always had a mental block when it comes to recursion. I understand it, but am unable to employ it as a tool. It seems like cheating to get a solution that is dependent on a solution using the self-referenced routine.

As such, how this routine is derived, ensuring that all of the digits are odd, is nearly magic to me. I would've tried a deconstruction/digit-checking routine that would certainly have been much slower, and much more of a memory hog.

Didier, is it possible for you to shed some light on how you approached this problem? It took me half an hour to understand how it works, and now that I do, I'm curious how you arrived at it. If you could dumb it down a bit, I'd be interested in the process.

Kudos to you for such an elegant solution.

Brad
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 - Brad Barton - 08-31-2017 12:49 PM



User(s) browsing this thread: