HHC 2018 Programming Contests
|
10-01-2018, 05:31 AM
(This post was last modified: 10-01-2018 06:04 AM by sasa.)
Post: #41
|
|||
|
|||
RE: HHC 2018 Programming Contests
The main problem is precise definition of "Extrema Date", which omit in this case. If we assume that the most correct representation is that event happens when at least two cycles have 100 and -100 (value is rounded), the event is much frequently.
In maximum predicted lifespan of 125 years: Code:
|
|||
10-01-2018, 06:09 AM
Post: #42
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 05:31 AM)sasa Wrote: The main problem is precise definition of "Extrema Date", which omit in this case. It was precisely defined in the original posting. If any aspect was imprecise, please let me know so that I can learn how to be more precise in the future. (10-01-2018 05:31 AM)sasa Wrote: In maximum predicted life of 125 years: 23 * 28 * 33 = 21252 days (roughly 58.2 years). In that period of time, there are precisely 320 different Maxima Days, 8 of which are *triple* Maxima Days (all three cycles are at 100 and/or -100). Yes, the minimum time between Maxima Days is 11 days. However, the maximum difference between consecutive Maxima Days is 196, not 380. <0|ɸ|0> -Joe- |
|||
10-01-2018, 06:21 AM
Post: #43
|
|||
|
|||
RE: HHC 2018 Programming Contests
Code:
# EF9Dh 537. |
|||
10-01-2018, 06:37 AM
Post: #44
|
|||
|
|||
RE: HHC 2018 Programming Contests
My take on elegance is a simple and concise program. That's what I present here; it contains several pre-calculated 'magic' numbers generated from the functions given in the challenge. It's probably not immediately obvious from the code exactly how they are derived, but that's what comments are for. So let's start with the general idea.
Each of the three functions has two extrema in their cycle, a maximum at a quarter of the cycle length and a minimum at three quarters of the cycle length. For the functions which don't have a cycle length evenly divisible by four, the example shows me that the rounded result of the division by four is enough. Experimentation has confirmed that, and it has also confirmed that the surrounding days are far enough away to yield function values with an absolute value of at most 99, which means we don't have to deal with extrema spanning more than a single day. From these observations we can easily calculate for each function the first few days on which it is at an extremum. For the 'physical' function (henceforth known as P): maximum at 5.75 (rounded to 6), minimum at 17.25 (rounded to 17), repeating every 23 days - Maxima (first 33): 6, 29, 52, 75, 98, 121, 144, 167, 190, 213, 236, 259, 282, 305, 328, 351, 374, 397, 420, 443, 466, 489, 512, 535, 558, 581, 604, 627, 650, 673, 696, 719, 742 - Minima (first 33): 17, 40, 63, 86, 109, 132, 155, 178, 201, 224, 247, 270, 293, 316, 339, 362, 385, 408, 431, 454, 477, 500, 523, 546, 569, 592, 615, 638, 661, 684, 707, 730, 753 For the 'emotional' function (henceforth known as E): maximum at 7, minimum at 21, repeating every 28 days - Maxima (first 33): 7, 35, 63, 91, 119, 147, 175, 203, 231, 259, 287, 315, 343, 371, 399, 427, 455, 483, 511, 539, 567, 595, 623, 651, 679, 707, 735, 763, 791, 819, 847, 875, 903 - Minima (first 33): 21, 49, 77, 105, 133, 161, 189, 217, 245, 273, 301, 329, 357, 385, 413, 441, 469, 497, 525, 553, 581, 609, 637, 665, 693, 721, 749, 777, 805, 833, 861, 889, 917 For the 'intellectual' function (henceforth known as I): maximum at 8.25 (rounded to 8), minimum at 24.75 (rounded to 25), repeating every 33 days - Maxima (first 28): 8, 41, 74, 107, 140, 173, 206, 239, 272, 305, 338, 371, 404, 437, 470, 503, 536, 569, 602, 635, 668, 701, 734, 767, 800, 833, 866, 899 - Minima (first 28): 25, 58, 91, 124, 157, 190, 223, 256, 289, 322, 355, 388, 421, 454, 487, 520, 553, 586, 619, 652, 685, 718, 751, 784, 817, 850, 883, 916 For every pair of functions (P and E, P and I, E and I) there is a number of days where they meet at 0 again and both ascend towards +100, just like they do at birth. That is, the pattern produced by drawing both functions of a pair repeats, and so do their extrema as well as the points where both have an extremum on the same day. The length of this repeating pattern is the product of lengths of the two functions' cycles. (Technically it should be the LCM (lowest common multiple), but since the cycles lengths don't have any common factor, that equates to the same number.) The next pre-processing task is therefore to find for each pair of functions the days on which they both have an extremum. For P and E the repeating pattern is 23 28 *, i.e. 644 days long, during which P goes through 28 cycles and E goes through 23. Looking at the first 28 maxima and minima of P as well as the first 23 maxima and minima of E, we find the common days 63 (minimum of P, maximum of E, the example), 259 (maximum of both), 385 (minimum of both), and 581 (maximum of P, minimum of E). For P and I the repeating pattern is 23 33 *, i.e. 759 days long, during which P goes through 33 cycles and I goes through 23. Looking at the first 33 maxima and minima of P as well as the first 23 maxima and minima of I, we find the common days 190 (maximum of P, minimum of I), 305 (maximum of both), 454 (minimum of both), and 569 (minimum of P, maximum of I). For E and I the repeating pattern is 28 33 *, i.e. 924 days long, during which E goes through 33 cycles and I goes through 28. Looking at the first 33 maxima and minima of E as well as the first 28 maxima and minima of I, we find the common days 91 (maximum of E, minimum of I), 371 (maximum of both), 553 (minimum of both), and 833 (minimum of E, maximum of I). With this data, the challenge can be rewritten like this: Given a number (representing the age in days, which is calculated as the difference between the birthdate and now), find the lowest number higher than the given number that is either: - equal to one of 63, 259, 385, 581, all modulo 644, or - equal to one of 190, 305, 454, 569, all modulo 759, or - equal to one of 91, 371, 553, 833, all modulo 924. The found number needs to be converted back to a date by adding it to the current date, of course. With this rewritten challenge in mind (or on hand), the code becomes relatively straight-forward. The input and output for this program are performed through the stack. This way the program blends in with normal calculator commands, and it's much less messy than the code for e.g. an input form. As a bonus, it even respects system flag 42 (date format mm.ddyyyy or dd.mmyyyy). Code: \<< Tests: A baby born last Friday (Sep 28, 2018), should have its first extrema date when it is 63 days old, which will happen on Nov 30, 2018. This is the example given in the challenge, and the graphs given there make it easy to tell if the function values are in the vicinity of the correct results. For input 28.092018 (my 50G has system flag 42 set, so that is the correct format) on stack level 1 my program outputs 30.112018 on stack level 2, and {P:(-100.) E:100. I:(-54.)} on stack level 1. Looks good so far, except for these weird parentheses around tagged negative numbers when they are on stack levels that get rendered in multiline mode. (I've set mine to only render level 1 in multiline mode.) Non-multiline stack levels have extra spaces at various places instead. Anyway, the data is fine. A baby born on Jan 1, 2018 has passed its first four extrema dates already. The next one should happen when it is 305 days old, i.e. on Nov 2, 2018. For input 1.012018 on stack level 1 my program outputs 2.112018 on stack level 2, and {P:100. E:(-62.) I:100.} on stack level 1. Yay, correct date. It appears my program can actually handle cases where the first result in the lists is not the best one. Now for some stress testing. After 23 28 33 * * days (that's 21252 days) all three functions are at their starting value of 0 again. A person who is exactly that much older than the baby from last Friday should therefore get the exact same output as the baby. 21252 days before Sep 28, 2018 is July 22, 1960 according to my 50G. (Enter 28.092018 -21252. DATE+ to confirm.) For input 22.071960 on stack level 1 my program outputs 30.112018 on stack level 2, and {P:(-100.) E:100. I:(-54.)} on stack level 1. Yaaay! It works with larger numbers too! ... So I can conclude that it does indeed work. |
|||
10-01-2018, 06:38 AM
Post: #45
|
|||
|
|||
RE: HHC 2018 Programming Contests
N.B. The contest entries WILL be posted here, but I must confess that I am TERRIBLY distracted at the moment with this brand new DM42 which I won during the Door Prize drawing at HHC 2018! I also won my very first HP-11C and an HP-17BII. Oh boy, new toys! Yowza wowza!!! Thanks to Dave Ramsey who donated the DM42 to the prize table, and Bob Prosperi who donated the HP-11C, and the generous anonymous soul who donated the 71BII! But don't worry, I'll put them down long enough to post the contest entries. Real Soon Now.
<0|ɸ|0> -Joe- |
|||
10-01-2018, 06:40 AM
(This post was last modified: 10-01-2018 09:14 PM by Thomas Klemm.)
Post: #46
|
|||
|
|||
RE: HHC 2018 Programming Contests
For each period \(p \in {23, 28, 33}\) we're looking for values such that
\(\sin(2 \pi \tfrac{k}{p})\approx \pm 1\) This leads to the following result: \( \begin{matrix} p=23 :& k \in \{6, 17\} \\ p=28 :& k \in \{7, 21\} \\ p=33 :& k \in \{8, 25\} \end{matrix} \) For each pair \((23, 28)\), \((23, 33)\) and \((28, 33)\) the "extrema dates" are calculated separately with the help of the Chinese remainder theorem which states that for numbers \(p\) and \(q\) that are coprime there's a ring isomorphism: \(\mathbb{Z}_{p}\times\mathbb{Z}_{q}\cong\mathbb{Z}_{p\cdot q}\). In the end the minimum of these three values is chosen. \(\mathbb{Z}_{23}\times\mathbb{Z}_{28}\cong\mathbb{Z}_{644}\) We're looking for a number \(n\) such that \((n \bmod 23, n \bmod 28) = (1, 0)\). Clearly \(n\) must be a multiple of \(28\): \(n = 28 \cdot k\). But then \(n \bmod 23 \equiv 5\cdot k\) and we can guess \(k=14\) since \(5 \cdot 14 = 70 = 1 + 3 \cdot 23 \equiv 1\ (\bmod 23)\). Thus we end up with: \(n = 28 \cdot 14 = 392 \equiv 1\ (\bmod 23)\). Similarly we can find a number \(m\) such that \((m \bmod 23, m \bmod 28) = (0, 1)\): \(m = 23 \cdot 11 = 253 = 1 + 9 \cdot 28 \equiv 1\ (\mod 28)\) Thus \((1, 0) \simeq 392\) and \((0, 1) \simeq 253\) form a basis in \(\mathbb{Z}_{23} \times \mathbb{Z}_{28}\). For \(a, b \in \mathbb{N}\) we find that: \((a, b) \simeq a \cdot 392 + b \cdot 253\ (\bmod 644)\) This leads to the following table: \( \begin{matrix} (6, 7) &\simeq& 6 \cdot 392 &+& 7 \cdot 253 &=& 4123 &\equiv& 259\ (\bmod\ 644) \\ (6, 21) &\simeq& 6 \cdot 392 &+& 21 \cdot 253 &=& 7665 &\equiv& 581\ (\bmod\ 644) \\ (17, 7) &\simeq& 17 \cdot 392 &+& 7 \cdot 253 &=& 8435 &\equiv& 63\ (\bmod\ 644) \\ (17, 21) &\simeq& 17 \cdot 392 &+& 21 \cdot 253 &=& 11977 &\equiv& 385\ (\bmod\ 644) \end{matrix} \) This explains the magic numbers in these lines of the program: Code: 07 63 ; (17, 7) \(\mathbb{Z}_{23}\times\mathbb{Z}_{33}\cong\mathbb{Z}_{759}\) As above we can find a basis using \((1, 0) \simeq 231\) and \((0, 1) \simeq 529\). We end up with this table: \( \begin{matrix} (6, 8) &\simeq& 6 \cdot 231 &+& 8 \cdot 529 &=& 5618 &\equiv& 305\ (\bmod\ 759) \\ (6, 25) &\simeq& 6 \cdot 231 &+& 25 \cdot 529 &=& 14611 &\equiv& 190\ (\bmod\ 759) \\ (17, 8) &\simeq& 17 \cdot 231 &+& 8 \cdot 529 &=& 8159 &\equiv& 569\ (\bmod\ 759) \\ (17, 25) &\simeq& 17 \cdot 231 &+& 25 \cdot 529 &=& 17152 &\equiv& 454\ (\bmod\ 759) \end{matrix} \) These are magic numbers of the program: Code: 29 190 ; (6, 25) \(\mathbb{Z}_{28}\times\mathbb{Z}_{33}\cong\mathbb{Z}_{924}\) As above we can find a basis using \((1, 0) \simeq 561\) and \((0, 1) \simeq 364\). We end up with this table: \( \begin{matrix} (7, 8) &\simeq& 7 \cdot 561 &+& 8 \cdot 364 &=& 6839 &\equiv& 371\ (\bmod\ 924) \\ (7, 25) &\simeq& 7 \cdot 561 &+& 25 \cdot 364 &=& 13027 &\equiv& 91\ (\bmod\ 924) \\ (21, 8) &\simeq& 21 \cdot 561 &+& 8 \cdot 364 &=& 14693 &\equiv& 833\ (\bmod\ 924) \\ (21, 25) &\simeq& 21 \cdot 561 &+& 25 \cdot 364 &=& 20881 &\equiv& 553\ (\bmod\ 924) \end{matrix} \) These are the magic numbers of the program: Code: 55 91 ; (7, 25) Here's the program for the HP-41CX: Code: 01▸LBL "NED" ; birthday Examples: The date-format DMY is used. 27.021963 XEQ "NED" NED: 14.11.2018 23: -100 28: -100 33: -76 01.011905 XEQ "NED" NED: 10.10.2018 23: -100 28: 62 33: 100 28.092018 XEQ "NED" NED: 30.11.2018 23: -100 28: 100 33: -54 Thanks for the challenge Thomas |
|||
10-01-2018, 09:54 AM
(This post was last modified: 10-01-2018 10:45 AM by sasa.)
Post: #47
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 06:09 AM)Joe Horn Wrote: It was precisely defined in the original posting. If any aspect was imprecise, please let me know so that I can learn how to be more precise in the future. According to your numbers, as someone read foreign language literally, I would formulate it as follows: If at least two extreme values happens simultaneously, let call that "Extrema Date". Extreme value is either 100 or -100. That would be clear for everyone, understanding that "Extrema Date" are when: 1. P= 100 E= any(including 100 or -100) I= 100 2. P= -100 E= -100 I= any(including 100 or -100) 3. P= 100 E= -100 I= any(including 100 or -100) Etc. Try to split your original sentence into two sentences according used conjunction and disjunction and you will probably notice that without additional therms (including or excluding pointer to example), meaning may be quite ambiguous. Quote:23 * 28 * 33 = 21252 days (roughly 58.2 years). In that period of time, there are precisely 320 different Maxima Days, 8 of which are *triple* Maxima Days (all three cycles are at 100 and/or -100). Yes, the minimum time between Maxima Days is 11 days. However, the maximum difference between consecutive Maxima Days is 196, not 380. With predicted maximum human lifespan of 125 years (45656 days) and with incorrectly assumed condition, values are exact. With reformulated precise definition, all is clear and figures now corrected accordingly. Assumption that non English readers may literally understand the content may help to formulate definition precisely. I'm not the only one here found original definition ambiguous. |
|||
10-01-2018, 10:46 AM
Post: #48
|
|||
|
|||
RE: HHC 2018 Programming Contests
Here is a slightly updated version of my PPL program, with some simplification, improvement in the results accuracy using ROUND instead of IP, and also using the Function App to do the calculation of the values for the extrema date, as well as to show graphically the different biorhythms centered around the next extrema date:
Code: EXPORT EXTREMA(BD) |
|||
10-01-2018, 01:42 PM
Post: #49
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 06:40 AM)Thomas Klemm Wrote: Here's the program for the HP-41CX: I think there's an RDN missing between lines 21 and 22. Moreover, the extrema cycle for 28 days is simply 7+14.n, reducing the number of comparisons from 12 to 8. The period for 23x28 and 28x33 days is also halved to 322 and 462, respectively. Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
10-01-2018, 08:38 PM
Post: #50
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 06:40 AM)Thomas Klemm Wrote: For each period \(p \in {23, 28, 33}\) we're looking for values such that..... Thomas...nice solution. BUT! We missed seeing you at the conference. Perhaps next year? ~ Jim ~ (Joe?) Put that DM42 down and post the winning solutions! ;-) |
|||
10-01-2018, 09:33 PM
Post: #51
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 01:42 PM)Werner Wrote: I think there's an RDN missing between lines 21 and 22. Thanks a lot for spotting the bug. Meanwhile I've fixed it in my post. Quote:Moreover, the extrema cycle for 28 days is simply 7+14.n, reducing the number of comparisons from 12 to 8. The period for 23x28 and 28x33 days is also halved to 322 and 462, respectively. This will take me a bit longer to adjust. But I'm glad there's still room for improvement. Honestly I don't consider my solution elegant. But then it was still fun to think about it. My first encounter with computers was probably in the late seventies when I could visit someone working in a chemistry lab. He had my biorhythm printed on a Commodore PET. And then he showed me his HP-67. So I guess that's where all that started. Therefore, there was probably a bit of nostalgia involved. Kind regards Thomas |
|||
10-01-2018, 09:47 PM
Post: #52
|
|||
|
|||
RE: HHC 2018 Programming Contests | |||
10-02-2018, 04:15 AM
Post: #53
|
|||
|
|||
RE: HHC 2018 Programming Contests
Gene…
Your post #37 exactly matches my approach. However, I did not bring a contest-legal calculator, so I didn't enter. This was my first HHC and I thoroughly enjoyed it (I never had time in my schedule to attend before). Thanks to the committee for organizing it and to the presenters for their talks and demonstrations. Also, congrats to Joe for winning the DM42. It's a great machine. Fred |
|||
10-02-2018, 06:10 AM
Post: #54
|
|||
|
|||
RE: HHC 2018 Programming Contests
Thomas Klemm Wrote:Honestly I don't consider my solution elegant. Well, on a 41, I'm not sure there's a more elegant way. And you managed to do it all in the stack ;-). Let's see what the HHC contenders came up with, they managed to surprise me time and again (Joe! Stop playing with that DM-42 ;-) Thomas Klemm Wrote:My first encounter with computers was probably in the late seventies when I could visit someone working in a chemistry lab. He had my biorhythm printed on a Commodore PET. And then he showed me his HP-67. So I guess that's where all that started. Therefore, there was probably a bit of nostalgia involved. I programmed biorhythms on my TI-58 (not 58C, sadly), also in the late seventees ;-) Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
10-02-2018, 08:11 AM
Post: #55
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 09:33 PM)Thomas Klemm Wrote:Quote:Moreover, the extrema cycle for 28 days is simply 7+14.n, reducing the number of comparisons from 12 to 8. The period for 23x28 and 28x33 days is also halved to 322 and 462, respectively. Here's the updated program: Code: 01▸LBL "NED" ; birthday Thanks again for your suggestion. Kind regards Thomas |
|||
10-02-2018, 04:33 PM
Post: #56
|
|||
|
|||
RE: HHC 2018 Programming Contests
Namir Shammas submitted this contest entry. Its elegance was unmatched (thankfully), and it gave me a good laugh.
The serious contest entries will be posted Real Soon Now. <0|ɸ|0> -Joe- |
|||
10-02-2018, 08:47 PM
Post: #57
|
|||
|
|||
RE: HHC 2018 Programming Contests
The announcement at HHC 2018 that the winner of the HP-41 RPN Programming Contest was Kerry Veenstra was prefaced by these comments:
"The winning RPN entry was considered 'most elegant' for several reasons. First of all, it used no trig to calculate the Extrema Dates, but instead used Number Theory to jump over non-Extrema Dates. This is not only a clever approach, but it also made the program fun to use, because unlike other approaches, it found the answer for any input very quickly. For example, the HP 50g programs which were submitted took an entire minute to find the answer for an input of 18 May 1975, but this HP-41 program finds the same answer in just 9 seconds! It was also accompanied by a thorough and clearly written program description giving program usage instructions, details of how it works, and an inline-commented listing, all typed up and elegantly printed." Kerry's submission, scanned into a PDF file, can be found here: http://hhuc.us/2018/contest/Veenstra.pdf More contest entries will be uploaded as time permits. <0|ɸ|0> -Joe- |
|||
10-03-2018, 04:20 AM
(This post was last modified: 10-03-2018 12:29 PM by Gerson W. Barbosa.)
Post: #58
|
|||
|
|||
RE: HHC 2018 Programming Contests
(10-01-2018 06:37 AM)3298 Wrote: For input 22.071960 on stack level 1 my program outputs 30.112018 on stack level 2, and {P:(-100.) E:100. I:(-54.)} on stack level 1. Hey, I am exactly one year younger (less old) than that person. That, except for the year, would have been my first example, but I chose 1.011905 to avoid ambiguities related to the user’s date format. I’ve changed my program to make it shorter and slightly less inelegant. Now 439 bytes, CK = #9AEh, but no nice output. Also, I don’t care about Extrema date falling on today’s date, but this time I haven’t forgotten to preserve the user’s angle mode. Running times don’t depend on the birthday dates, taking about eight tenths of a second. I haven’t tested yours yet, but I guess it should be even faster. (Update: yours take about half a second). Nicely documented, well done! ---------------- PS.: My program fails for 22 Feb 1950. Instead of 30 Jan 2019 it returns 29 Mar 2019. |
|||
10-03-2018, 12:39 PM
Post: #59
|
|||
|
|||
RE: HHC 2018 Programming Contests | |||
10-03-2018, 02:03 PM
Post: #60
|
|||
|
|||
RE: HHC 2018 Programming Contests
I don't like programs to change settings, so here's how to keep the display settings and the trig mode when calculating the biorhythm with period p for d days:
In: Y: d X: p Out: % rounded to the nearest integer Code: ▸LBL 14 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)