HHC 2015 RPL Programming Contest
|
10-05-2015, 01:48 PM
Post: #1
|
|||
|
|||
HHC 2015 RPL Programming Contest
Could someone post the HHC 2015 RPL Programming Contest? I'm looking at you Bill Butler....
Dave |
|||
10-07-2015, 01:59 PM
Post: #2
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
Bill sent me an email with the contest handout. It is attached.
Dave |
|||
10-07-2015, 04:59 PM
(This post was last modified: 10-07-2015 05:00 PM by C.Ret.)
Post: #3
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
Not sure this is the fastest way of doing it.
But it is simple: Code: « 1. * DUP SORT ΔLIST SWAP ISPRIME? + 0. POS NOT » It is the concatenation of the two tests: A list of distinct numbers: Code: « SORT ΔLIST 0. POS NOT » A list of primes: Code: « ISPRIME? 0. POS NOT » The 1. * is only here to convert the list of exact integer (aka TYPE 28) into regular 'dot' integers (aka TYPE 0). The ISPRIME? function aways returns 0. or 1. 'dot' integer. |
|||
10-08-2015, 04:42 AM
Post: #4
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
(10-07-2015 04:59 PM)C.Ret Wrote: The 1. * is only here to convert the list of exact integer (aka TYPE 28) into regular 'dot' integers (aka TYPE 0). RPL has a I→R function for that purpose. <0|ɸ|0> -Joe- |
|||
10-08-2015, 03:57 PM
Post: #5
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
Oh! Thank you, I miss this instruction.
I also just realise that the 'dot integers' are in fact just reals; Sorry for that, I am new in HP-50g, I am only a native user of HP-28's RPL ! So, I have to post a new version, a Joe Horn version : Code: « I→R DUP SORT ΔLIST SWAP ISPRIME? + 0. POS NOT » But I am in trouble, I am not confident in this code, due to the SORT instruction that may be slow on large lists |
|||
10-20-2015, 02:18 AM
Post: #6
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
I worry that your solution won't work if the list contains integers that exceed to precision of real numbers.
I thought of a way to do it without sorting: the list is distinct primes if the least common multiple of the list is the same as the product of the list: Code: « DUP œLIST SWAP @ Put product of list in lvl 2 But this isn't quite right. If the list contains one or more copies of 1, it will incorrectly report that it is distinct primes. My next attempt was faster so I abandoned this. Here's a version that tries to take advantage of the large size of the list. It exits as soon as it finds a duplicate or a non-prime. This takes advantage of DOLIST and error processing for speed, and to get a consistent stack when it's done. Code: « |
|||
10-20-2015, 01:03 PM
Post: #7
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
(10-20-2015 02:18 AM)David Hayden Wrote: I generated a list of the first 250 primes larger than 8000. If finishes this list in 20.65 seconds (on the emulator set at authentic speed). But if I add 88 to the list, it finishes in just 12.13 seconds. Don't be so afraid to use SORT, the following code: Code:
Runs the same list of 250 primes bigger than 8000 on 11.9 seconds on a real 50g. Adding the number 88 at the end does it in 7.2 seconds. |
|||
10-20-2015, 02:47 PM
(This post was last modified: 10-21-2015 07:13 AM by Gerald H.)
Post: #8
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
Edit: See next posting, author of quoted programme is Werner Huysegoms. Thank you, Jacob, for the reference.
If you want to sort a list of integers (no dots) quickly, try this: Code:
I can't remember where I found the programme - I'm definitely not the originator. (Anyone know who wrote it?) |
|||
10-20-2015, 11:28 PM
Post: #9
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
(10-20-2015 02:47 PM)Gerald H Wrote: I can't remember where I found the programme - I'm definitely not the originator. (Anyone know who wrote it?) That would appear to be LSort, written by Werner Huysegoms, indeed very fast http://www.hpcalc.org/details.php?id=2828 |
|||
10-21-2015, 07:16 AM
Post: #10
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
I don't know (any more) how to compile that (in EMU48), so I can't be sure.
If it's mine it'll be the one from hpcalc.org, that's v0.4. I have a more recent version (prompted by your request last year, Jacob) that corrects a number of bugs, and includes binary integers (supporting wordsize). No, no speed gain - I squeezed the max out of that already. The only thing missing is units support, and that will most probably never make it, the 'sort engine' can't support it. I'll see if I can upload it (well, them, as now there's a 48 and a 49/50 version, due to 'getwordsize' being unsupported and in different places. If anyone would know how to get the wordsize within an ASM program, independent of the model, that would be great). Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
10-24-2015, 12:23 AM
Post: #11
|
|||
|
|||
RE: HHC 2015 RPL Programming Contest
(10-21-2015 07:16 AM)Werner Wrote: The only thing missing is units support, and that will most probably never make it, the 'sort engine' can't support it. Good to hear you did some work with LSort, and IMHO unit support isn't a big deal, others may disagree. Unfortunately I am of no help regarding your wordsize query within ASM. Did you manage to implement a "natural" order sorting algorithm for strings? Much later after our discussions it dawned on me that if I wanted a more "natural" order for strings (especially for strings containing numeric values) I could simply pad all the strings with spaces (or any character really) so that the content is right justified with empty place holders to the left, then the standard sting sorting algorithms would probably handle them just fine and result in a sort order that I would prefer. One would simply need to check for the longest string, then pad all other strings to the same length. After sort, removing spaces and be done with it. I never got around to benchmarking such a implementation with System RPL, but in theory it shouldn't take that long even for 1000 elements in a list. Jacob |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)