Post Reply 
RPL Mini-Challenge: All Odd Digits?
07-03-2017, 01:18 AM
Post: #10
RE: RPL Mini-Challenge: All Odd Digits?
@Joe: Nice mini-challenge! I'm glad to see you are still exercising your RPL skills. And I'm also pleased to see that you've specified a balanced approach for scoring this one. All the work I've been doing with lists lately has really underscored the importance of considering speed and memory issues along with code size.

My submission:

I decided to try a different tactic for this challenge, though it's still not quite as fast as Joe's. This one has a size of 45 bytes, and clocks in on my 50g at 0.1222 seconds. That gives me a score of about 5.5 on the 1000-digit numbers:

Code:
\<<
  @ convert integer to string
  \->STR

  @ obtain number of digits
  DUP SIZE

  @ create a mask of 1s for the given length
  R\->I ALOG 1 - 9 / \->STR

  @ save a copy of the mask, then apply it to mark all odd digit positions
  DUP UNROT AND

  @ if the result is the same as the mask, all digits were odd
  ==
\>>

*Note that the calculator has to already be in exact mode when you transfer (or edit) the above program, otherwise the 1 and 9 constants will get compiled as reals instead of integers. The program won't work if that happens. I believe this is still in keeping with the specified rules of the challenge, though.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: RPL Mini-Challenge: All Odd Digits? - DavidM - 07-03-2017 01:18 AM



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