RPL Mini-Challenge: All Odd Digits?
|
07-02-2017, 04:25 AM
Post: #1
|
|||
|
|||
RPL Mini-Challenge: All Odd Digits?
Here's a mini-challenge for HP 49 & HP 50 programmers.
Purpose of program: Test whether a number contains only odd digits. Input: Any positive exact integer (that is, exact-mode integer-type objects only, no reals or negatives allowed). Invalid inputs need not be tested for. Output: 1 (meaning "true") if the input contains only odd digits. 0 (meaning "false") if the input contains any even digits. Examples: 1357335 --> 1 (True; all digits are odd) 1357325 --> 0 (False; there's an even digit in there) 1234567 --> 0 (False; not all digits are odd) 0 --> 0 (False; 0 is even) The winner is determined by speed * bytes (execution in seconds, times size of program without name) on 1000-digit inputs. My current best score is roughly 4.8. <0|ɸ|0> -Joe- |
|||
07-02-2017, 06:37 AM
(This post was last modified: 07-02-2017 10:05 AM by Gerald H.)
Post: #2
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
A first suggestion:
Code:
Time in seconds for 1000th repunit (worst case) .13 sec byte size of programme 84.5 giving a score of 10.95 Edit: As most 1000 digit numbers contain a zero, average score would be 5.2 |
|||
07-02-2017, 09:42 AM
Post: #3
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
This will be easily a new processing list challenge! Thanks for the input.
Wikis are great, Contribute :) |
|||
07-02-2017, 10:02 AM
(This post was last modified: 07-02-2017 10:06 AM by Gerald H.)
Post: #4
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
Slightly shortened version:
Code:
Score on average now 5.07 |
|||
07-02-2017, 10:18 AM
Post: #5
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
Further slightly shorter version:
Code:
Average score now 5.07 |
|||
07-02-2017, 03:55 PM
(This post was last modified: 07-02-2017 09:43 PM by Gilles59.)
Post: #6
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
With the GoferList Library :
Code:
Short but slow (24sec) in the worst case (1000 digits all odd). I think SREPL is a (the) key ;D PS : Code:
|
|||
07-02-2017, 07:53 PM
(This post was last modified: 07-02-2017 09:26 PM by Gilles59.)
Post: #7
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
(07-02-2017 10:18 AM)Gerald H Wrote: Further slightly shorter version: Hi Gerald, what do you mean with "average score" ? Joe, how do you calculate the execution time ? Is it in the worst case? This code is a variation of Gerald program but shorter and little faster : Code:
67 bytes Execution time on 1000-digit inputs : Best case : 0.0619 s (101...111) Worst case : 0.1351 s (111...111) SREPL is very fast. I suspect it is ARM coded. |
|||
07-02-2017, 09:55 PM
(This post was last modified: 07-02-2017 10:09 PM by Gilles59.)
Post: #8
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
Another Idea
Code: « |
|||
07-03-2017, 12:24 AM
Post: #9
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
Wow so many ideas. Here is mine.
« STR 1 SWAP WHILE DUP HEAD OBJ 2 MOD ROT AND SWAP TAIL DUP2 SIZE AND REPEAT END DROP » |
|||
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: \<< *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. |
|||
07-03-2017, 06:40 AM
(This post was last modified: 07-03-2017 06:44 AM by Gerald H.)
Post: #11
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
Using Gilles version of my prog at 67 bytes & time for a zero inclusive 1000 digit .065 sec gives a score of 4.3
|
|||
07-03-2017, 06:50 AM
Post: #12
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
Taking the product of 900th repunit & 10^100 as the average input, I get using Gilles version a time of .071 sec & size of 67, giving a score of 4.75
|
|||
07-03-2017, 07:33 AM
Post: #13
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits? | |||
07-03-2017, 07:48 AM
Post: #14
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
(07-03-2017 07:33 AM)Dieter Wrote:(07-03-2017 06:50 AM)Gerald H Wrote: Taking the product of 900th repunit & 10^100 as the average input, I get using Gilles version a time of .071 sec & size of 67, giving a score of 4.75 Please see post #1 for method of evaluating score. |
|||
07-03-2017, 07:52 AM
(This post was last modified: 07-03-2017 08:26 AM by Gilles59.)
Post: #15
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
(07-03-2017 01:18 AM)DavidM Wrote: 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: Very interesting David! I dont have my 50G here, but I think there is a way to improve speed of the part : Code: R\->I ALOG 1 - 9 / \->STR I think at something like : Code:
|
|||
07-03-2017, 07:53 AM
Post: #16
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits? | |||
07-03-2017, 10:26 AM
Post: #17
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
(07-03-2017 07:52 AM)Gilles59 Wrote: Very interesting David! I tried some variants of the above, but found that the version I posted ended up being faster, at least on a real 50g vs. Emu48. This is one of those cases where the performance on Emu48 is misleading when compared to a real 50g. When I use your code instead of the first version posted, the overall speed on a real 50g goes from 0.1222 seconds to around 0.167. The SREPL version is faster on Emu48, though, probably because Emu48 doesn't emulate the ARM layer. So I guess it depends on what platform you're targeting. Unfortunately the SREPL version is also about 15 bytes longer, so it not only slows down but also raises the score on that front as well. I've been assuming that Joe's scoring method is based on the results of size/performance as measured on a real calculator as opposed to an emulated one. |
|||
07-03-2017, 10:29 AM
Post: #18
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
My take:
Code: \<< \->STR { "0" "2" "4" "6" "8" } POS \GSLIST NOT \>> Now what would constitute "average" input? |
|||
07-03-2017, 11:33 AM
Post: #19
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
For an average number, in this case
1(100*)2(100*)3(100*)4(...............*)9(100*)*10^100 Gilles programme requires .057 sec, giving a score of 3.84 The notation 1(100*) indicates a concatenation of 100 1s. |
|||
07-04-2017, 02:11 AM
(This post was last modified: 07-04-2017 02:14 AM by Joe Horn.)
Post: #20
|
|||
|
|||
RE: RPL Mini-Challenge: All Odd Digits?
(07-02-2017 07:53 PM)Gilles59 Wrote: Joe, how do you calculate the execution time? I put the input number on the stack, then recall the program itself onto the stack, then execute TEVAL (which I keep assigned to a key). (07-03-2017 10:26 AM)DavidM Wrote: I've been assuming that Joe's scoring method is based on the results of size/performance as measured on a real calculator as opposed to an emulated one. Correct. Otherwise the "score" would be meaningless, allowing crummy code on a fast computer to beat elegant code on a slower computer. <0|ɸ|0> -Joe- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)