HHC 2015 RPL Programming Contest - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HHC 2015 RPL Programming Contest (/thread-4885.html) |
HHC 2015 RPL Programming Contest - David Hayden - 10-05-2015 01:48 PM Could someone post the HHC 2015 RPL Programming Contest? I'm looking at you Bill Butler.... Dave RE: HHC 2015 RPL Programming Contest - David Hayden - 10-07-2015 01:59 PM Bill sent me an email with the contest handout. It is attached. Dave RE: HHC 2015 RPL Programming Contest - C.Ret - 10-07-2015 04:59 PM 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. RE: HHC 2015 RPL Programming Contest - Joe Horn - 10-08-2015 04:42 AM (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. RE: HHC 2015 RPL Programming Contest - C.Ret - 10-08-2015 03:57 PM 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 RE: HHC 2015 RPL Programming Contest - David Hayden - 10-20-2015 02:18 AM 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: « RE: HHC 2015 RPL Programming Contest - Claudio L. - 10-20-2015 01:03 PM (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. RE: HHC 2015 RPL Programming Contest - Gerald H - 10-20-2015 02:47 PM 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?) RE: HHC 2015 RPL Programming Contest - Jacob Wall - 10-20-2015 11:28 PM (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 RE: HHC 2015 RPL Programming Contest - Werner - 10-21-2015 07:16 AM 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 RE: HHC 2015 RPL Programming Contest - Jacob Wall - 10-24-2015 12:23 AM (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 |