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
 sasa Member Posts: 116 Joined: Apr 2018
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:
 Events count: 348   Min diff (days): 11   Max diff (days): 380   Total days : 45656
10-01-2018, 06:09 AM
Post: #42
 Joe Horn Senior Member Posts: 1,892 Joined: Dec 2013
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:
Code:
 Events count: 348   Min diff (days): 11   Max diff (days): 380   Total days : 45656

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
 Gerson W. Barbosa Senior Member Posts: 1,473 Joined: Dec 2013
RE: HHC 2018 Programming Contests
Code:
 « RAD DUP DATE DUP UNROT DDAYS 3. NDUPN →LIST { 644. 924. 759. } MOD { } SWAP DUP 1. GET 5. NDUPN →LIST { 63. 259. 385. 581. 1644. } SWAP - DUP 0. > *   WHILE DUP HEAD NOT   REPEAT TAIL   END 1. GET ROT + SWAP DUP 2. GET 5. NDUPN →LIST { 91. 371. 553. 833. 1924. } SWAP - DUP 0. > *   WHILE DUP HEAD NOT   REPEAT TAIL   END 1. GET ROT + SWAP DUP 3. GET 5. NDUPN →LIST { 190. 305. 454. 569. 1759. } SWAP - DUP 0. > *   WHILE DUP HEAD NOT   REPEAT TAIL   END 1. GET ROT + SWAP DROP SORT OBJ→ DROP DROP2 DATE+ DUP UNROT DDAYS DUP + π * DUPDUP →V3 AXL { 23. 28. 33. } / SIN »

# EF9Dh
537.
10-01-2018, 06:37 AM
Post: #44
 3298 Member Posts: 182 Joined: Oct 2014
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:
\<<   DATE DDAYS                                    (convert the birthdate given on the stack into an age in days)   1. +                                          (when today is an extrema day, we don't want to get told about that, but rather about the next extrema day, but modulo arithmetics can easily return 0 as result (i.e. 0 days from now -> today); doing special cases for that is much more messy than simply starting the calculations with tomorrow as input)   \-> age \<<     { 644. 759. 924. }                          (lengths of the repeating patterns for each function pair, in the same order as the common extrema lists below)     {       { 63. 259. 385. 581. }                    (common extrema for the function pair P and E)       { 190. 305. 454. 569. }                   (same for P and I)       { 91. 371. 553. 833. }                    (same for E and I)     }     2.                                          (I'm going to use DOLIST to apply the same processing to every function pair; DOLIST needs to know that it gets two lists)     \<<                                                 (all calculations in here should be thought of as modulo the length of the repeating pattern; this is enforced by the MOD below)       age                                       (in this modulo this tells us how far we are in the pattern)       -                                         (subtracting the position in the pattern from the positions of the common extrema tells us how far the next occurence of each of the common extrema is; the beauty of modulo arithmetics is that any that have already passed get wrapped around to their next occurence)       OVER MOD                                  (I'm done doing arithmetics, now I want to compare, so the modulo needs to be applied now)       1. \<< MIN \>> DOLIST                     (give me the smallest element of the list; the easiest way to do that is with the MIN command which takes two parameters, and feed the list to it one by one using DOLIST; the starting value for that is the modulo (which was still on the stack) because it is guaranteed to be bigger than the list elements)     \>> DOLIST                                  (after this we have a list of how many days in the future the next extrema date involving each function pair is)     1000. SWAP 1. \<< MIN \>> DOLIST            (reduce the list to its smallest value using the same trick as above; this time the starting value is 1000, which is bigger than the possible day counts because it's bigger than the biggest modulo)     DUP age + 'age' STO                         (calculate age for the next maxima day, in order to display the function values on that day)     1. +                                        (remember, the calculations were based on tomorrow; adjust them to be based on today)     DATE SWAP DATE+ "Next extrema date" \->TAG  (tell the user what date corresponds to N days from now, and tag it appropriately)     RCLF RAD                                    (preserve user's angle mode and switch to radians, because calculating the functions involves SIN which depends on the angle mode for correct results)     { "P" "E" "I" }                             (names of the functions for tagging)     { 23. 28. 33. }                             (cycle lengths of the functions)     2.                                          (another DOLIST upcoming ... two lists for this one again)     \<<       age SWAP / 2. \pi * * SIN 100. *          (calculate the function for the cycle length on the stack; if this needs any explanation, go back to school and pay attention during trig lessons)       0. RND                                    (the challenge specifies that the function values shall always be rounded to the nearest integer)       SWAP \->TAG                               (tag it)     \>> DOLIST     SWAP STOF                                   (restore user's angle mode)   \>> \>>
At least it's more elegant than the efficiency-focused programs I usually write. It's still quite efficent, the only obvious optimization would be to remove the first 1 + and decrement all the common extrema to compensate, but doing that would make it a bit harder to follow.

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
 Joe Horn Senior Member Posts: 1,892 Joined: Dec 2013
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
 Thomas Klemm Senior Member Posts: 1,804 Joined: Dec 2013
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) 11 259              ; (6, 7) 15 385              ; (17, 21) 19 581              ; (6, 21)

$$\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) 33 305              ; (6, 8) 37 454              ; (17, 25) 41 569              ; (17, 8)

$$\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) 59 371              ; (7, 8) 63 553              ; (21, 25) 67 833              ; (21, 8)

Here's the program for the HP-41CX:
Code:
01▸LBL "NED"        ; birthday 02 DATE             ; today 03 DDAYS            ; n days difference 04 RCL X            ; n         n 05 644              ; = 23 × 28 06 MOD              ; u=n%644   n 07 63               ; (17, 7) 08 X>Y?             ; 63 > u ? 09 GTO 00           ; found next U 10 RDN              ; u         n 11 259              ; (6, 7) 12 X>Y?             ; 259 > u ? 13 GTO 00           ; found next U 14 RDN              ; u         n 15 385              ; (17, 21) 16 X>Y?             ; 385 > u ? 17 GTO 00           ; found next U 18 RDN              ; u         n 19 581              ; (6, 21) 20 X>Y?             ; 581 > u ? 21 GTO 00           ; found next U 22 RDN              ; u         n 23 707              ; = 644 + 63 24▸LBL 00           ; U         u       n 25 X<>Y             ; u         U       n 26 -                ; ∆u        n 27 RCL Y            ; n         ∆u      n 28 759              ; = 23 × 33 29 MOD              ; v=n%759   ∆u      n 30 190              ; (6, 25) 31 X>Y?             ; 190 > v ? 32 GTO 00           ; found next V 33 RDN              ; v         ∆u      n 34 305              ; (6, 8) 35 X>Y?             ; 305 > v ? 36 GTO 00           ; found next V 37 RDN              ; v         ∆u      n 38 454              ; (17, 25) 39 X>Y?             ; 454 > v ? 40 GTO 00           ; found next V 41 RDN              ; v         ∆u      n 42 569              ; (17, 8) 43 X>Y?             ; 569 > v ? 44 GTO 00           ; found next V 45 RDN              ; v         ∆u      n 46 949              ; = 759 + 190 47▸LBL 00           ; V         v       ∆u      n 48 X<>Y             ; v         V       ∆u      n 49 -                ; ∆v        ∆u      n       n 50 X<Y?             ; ∆v < ∆u ? 51 X<>Y             ; max       min     n       n 52 RDN              ; min       n       n 53 X<>Y             ; n         min     n 54 924              ; = 28 × 33 55 MOD              ; w=n%924   min     n 56 91               ; (7, 25) 57 X>Y?             ; 91 > w ? 58 GTO 00           ; found next W 59 RDN              ; w         min     n 60 371              ; (7, 8) 61 X>Y?             ; 371 > w ? 62 GTO 00           ; found next W 63 RDN              ; w         min     n 64 553              ; (21, 25) 65 X>Y?             ; 553 > w ? 66 GTO 00           ; found next W 67 RDN              ; w         min     n 68 833              ; (21, 8) 69 X>Y?             ; 833 > w ? 70 GTO 00           ; found next W 71 RDN              ; w         min     n 72 1015             ; = 924 + 91 73▸LBL 00           ; W         w       min     n 74 X<>Y             ; w         W       min     n 75 -                ; ∆w        min     n       n 76 X<Y?             ; ∆w < min ? 77 X<>Y             ; max       min 78 RDN              ; min       n       n 79 +                ; m = n + min 80 DATE             ; today     m       n       n 81 LASTX            ; min       today   m       n 82 DATE+            ; today+min m       n       n 83 "NED: "          ; show next extrema date 84 FIX 6            ; 85 ADATE            ; 86 AVIEW            ; 87 RDN              ; m         n 88 23               ; 23        m       n 89 XEQ 00           ; show 23 90 28               ; 28        m       n 91 XEQ 00           ; show 28 92 33               ; 33        m       n 93▸LBL 00           ; show p 94 FIX 0            ; 95 CLA              ; "" 96 ARCL X           ; "p" 97 ├": "            ; "p: " 98 RCL Y            ; m         p       m       n 99 X<>Y             ; p         m       m       n 100 /               ; m/p       m       n       n 101 360             ; 360       m/p     m       n 102 *               ; 360*m/p   m       n       n 103 SIN             ; value     m       n       n 104 100             ; 100       value   m       n 105 *               ; %value    m       n       n 106 ARCL X          ; "p: %value" 107 FIX 6           ; 108 AVIEW           ; 109 RDN             ; m         n       n 110 END             ;

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
 sasa Member Posts: 116 Joined: Apr 2018
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
 Didier Lachieze Senior Member Posts: 1,524 Joined: Dec 2013
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) BEGIN   LOCAL d1,d3;   // Find Next Extrema date   N:=DDAYS(BD,Date);   A:=IP(2*N/23-1/2);   B:=IP(2*N/28-1/2);   C:=IP(2*N/33-1/2);   L1:=MAKELIST(23/2*(1/2+I),I,A+1,A+33); L4:=IP(L1);   L2:=MAKELIST(28/2*(1/2+I),I,B+1,B+33);   L3:=MAKELIST(33/2*(1/2+I),I,C+1,C+33); L5:=IP(L3);   D:=MIN(head(INTERSECT(L4,L2)),head(INTERSECT(L2,L5)),head(INTERSECT(L4,L5))​);   E:=DATEADD(BD,D);   // Display results using the Function App: first text, then a graphic view centered on the next extrema   STARTAPP("Function");   F1:='100*SIN(4*ACOS(0)*(X MOD 23)/23)';   F2:='100*SIN(4*ACOS(0)*(X MOD 28)/28)';   F3:='100*SIN(4*ACOS(0)*(X MOD 33)/33)';   Xmin:=D-40; Xmax:=D+40; Ymin:=-110; Ymax:=110;  Xtick:=5; Ytick:=10;   PRINT("Birthday : "+STRING(BD,2,4));   PRINT("Next Extrema Date: "+STRING(E,2,4));   d1:=IFTE(POS(L4,D),L1(POS(L4,D)),D);   d3:=IFTE(POS(L5,D),L3(POS(L5,D)),D);   PRINT("Physical: "+ROUND(F1(d1),0));   PRINT("Emotional: "+ROUND(F2(D),0));   PRINT("Intellectual: "+ROUND(F3(d3),0));   CHECK({1,2,3});UNCHECK({0,4,5,6,7,8,9});   STARTVIEW(1);   RETURN E; END;

Attached File(s) Thumbnail(s)

10-01-2018, 01:42 PM
Post: #49
 Werner Senior Member Posts: 737 Joined: Dec 2013
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
10-01-2018, 08:38 PM
Post: #50
 jjohnson873 Member Posts: 192 Joined: Dec 2013
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.....

Thanks for the challenge
Thomas

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
 Thomas Klemm Senior Member Posts: 1,804 Joined: Dec 2013
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
 Thomas Klemm Senior Member Posts: 1,804 Joined: Dec 2013
RE: HHC 2018 Programming Contests
(10-01-2018 08:38 PM)jjohnson873 Wrote:  We missed seeing you at the conference. Perhaps next year? ~ Jim ~

That's a nice remark, I really appreciate it.
It's just that I don't like to travel that far anymore.
But I signed up for the Allschwil Meeting.

Kind regards
Thomas
10-02-2018, 04:15 AM
Post: #53
 Fred Lusk Junior Member Posts: 12 Joined: Dec 2013
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
 Werner Senior Member Posts: 737 Joined: Dec 2013
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
10-02-2018, 08:11 AM
Post: #55
 Thomas Klemm Senior Member Posts: 1,804 Joined: Dec 2013
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.

This will take me a bit longer to adjust.

Here's the updated program:
Code:
01▸LBL "NED"        ; birthday 02 DATE             ; today 03 DDAYS            ; n days difference 04 RCL X            ; n         n 05 322              ; = 23 × 14 06 MOD              ; u=n%322   n 07 63               ; (17, 7) 08 X>Y?             ; 63 > u ? 09 GTO 00           ; found next U 10 RDN              ; u         n 11 259              ; (6, 7) 12 X>Y?             ; 259 > u ? 13 GTO 00           ; found next U 14 RDN              ; u         n 15 385              ; = 322 + 63 16▸LBL 00           ; U         u       n 17 X<>Y             ; u         U       n 18 -                ; ∆u        n 19 RCL Y            ; n         ∆u      n 20 759              ; = 23 × 33 21 MOD              ; v=n%759   ∆u      n 22 190              ; (6, 25) 23 X>Y?             ; 190 > v ? 24 GTO 00           ; found next V 25 RDN              ; v         ∆u      n 26 305              ; (6, 8) 27 X>Y?             ; 305 > v ? 28 GTO 00           ; found next V 29 RDN              ; v         ∆u      n 30 454              ; (17, 25) 31 X>Y?             ; 454 > v ? 32 GTO 00           ; found next V 33 RDN              ; v         ∆u      n 34 569              ; (17, 8) 35 X>Y?             ; 569 > v ? 36 GTO 00           ; found next V 37 RDN              ; v         ∆u      n 38 949              ; = 759 + 190 39▸LBL 00           ; V         v       ∆u      n 40 X<>Y             ; v         V       ∆u      n 41 -                ; ∆v        ∆u      n       n 42 X<Y?             ; ∆v < ∆u ? 43 X<>Y             ; max       min     n       n 44 RDN              ; min       n       n 45 X<>Y             ; n         min     n 46 462              ; = 14 × 33 47 MOD              ; w=n%462   min     n 48 91               ; (7, 25) 49 X>Y?             ; 91 > w ? 50 GTO 00           ; found next W 51 RDN              ; w         min     n 52 371              ; (7, 8) 53 X>Y?             ; 371 > w ? 54 GTO 00           ; found next W 55 RDN              ; w         min     n 56 553              ; = 462 + 91 57▸LBL 00           ; W         w       min     n 58 X<>Y             ; w         W       min     n 59 -                ; ∆w        min     n       n 60 X<Y?             ; ∆w < min ? 61 X<>Y             ; max       min 62 RDN              ; min       n       n 63 +                ; m = n + min 64 DATE             ; today     m       n       n 65 LASTX            ; min       today   m       n 66 DATE+            ; today+min m       n       n 67 "NED: "          ; show next extrema date 68 FIX 6            ; 69 ADATE            ; 70 AVIEW            ; 71 RDN              ; m         n 72 23               ; 23        m       n 73 XEQ 00           ; show 23 74 28               ; 28        m       n 75 XEQ 00           ; show 28 76 33               ; 33        m       n 77▸LBL 00           ; show p 78 FIX 0            ; 79 CLA              ; "" 80 ARCL X           ; "p" 81 ├": "            ; "p: " 82 RCL Y            ; m         p       m       n 83 X<>Y             ; p         m       m       n 84 /                ; m/p       m       n       n 85 360              ; 360       m/p     m       n 86 *                ; 360*m/p   m       n       n 87 SIN              ; value     m       n       n 88 100              ; 100       value   m       n 89 *                ; %value    m       n       n 90 ARCL X           ; "p: %value" 91 FIX 6            ; 92 AVIEW            ; 93 RDN              ; m         n       n 94 END              ;

Kind regards
Thomas
10-02-2018, 04:33 PM
Post: #56
 Joe Horn Senior Member Posts: 1,892 Joined: Dec 2013
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
 Joe Horn Senior Member Posts: 1,892 Joined: Dec 2013
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
 Gerson W. Barbosa Senior Member Posts: 1,473 Joined: Dec 2013
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
 Eddie W. Shore Senior Member Posts: 1,383 Joined: Dec 2013
RE: HHC 2018 Programming Contests
(10-02-2018 04:33 PM)Joe Horn Wrote:  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.

LOL
10-03-2018, 02:03 PM
Post: #60
 Werner Senior Member Posts: 737 Joined: Dec 2013
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  1/X  %  4  10↑X  ×  3.6  FS? 42  →HR  ×  FS? 43  →RAD  SIN  200  ×  ENTER  SIGN  +  2  ÷  IP  RTN
 « Next Oldest | Next Newest »

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