HHC 2018 Programming Contests
10-06-2018, 04:21 PM
Post: #84
 3298 Member Posts: 190 Joined: Oct 2014
RE: HHC 2018 Programming Contests
(10-06-2018 12:48 PM)Thomas Klemm Wrote:  But I consider 3298's idea to calculate the difference, then the remainder, flatten the lists and only then sort the result more elegant.
Thank you very much.
(10-06-2018 12:48 PM)Thomas Klemm Wrote:  Only drawback is the use of:
Code:
1. +
If those shall go entirely, try replacing the inner program
Code:
\<< - SWAP MOD \>>
with this:
Code:
\<<   - OVER MOD   DUP 0. == ROT * + \>>
... and remove both instances of 1. +.
I've taken inspiration from Gerson's program here, he thought of using comparisons for list processing first. This variant is 5 bytes longer though.

Another bit that could make all of our programs more elegant would be using units in the function values calculation to avoid that mode switching madness. (By the way, Thomas, your mashup program blindly assumes DEG mode and failed to return correct results on my calculator for that reason.) There are dedicated units for angles, and when SIN gets an input tagged with one of these, the unit overrides the current angle mode.
Unfortunately unit objects are pretty heavy, adding 13.5 bytes to the number they are attached to (that number is for single-symbol units like degrees and radians; longer units take even more). That's more than what we spend for the mode switching (12.5 bytes in my program).

Next discovery: exploding a sublist inside DOLIST (e.g. with an EVAL at the end of the program passed to DOLIST) causes all elements of the sublist to be added to the result list, no more flattening needed. That means, adding an EVAL at the end of the subprogram lets me remove the EVAL + + after the DOLIST. That's 5 bytes saved with no negative impact on elegance (if anything, it's more elegant afterwards).

And then there's a rare and kind of amusing bug. If my program (or the one by Thomas that's partially based on mine) runs during midnight, there's a chance the DATE calls happen on different sides of midnight and therefore return different values. That causes the calculated extrema date to be off by one. The function values remain correct though. I've corrected this in the revised "elegant" version below.

But before we come to that let's do something different, trying to get my program as short as possible. Of course that means doing exactly what I just criticized Thomas' program for, blindly assuming that the angle mode is radians (because that's what matches a freshly reset calculator, which the challenge demands programs to be compatible with). The midnight bug stays in. No pretty tagging either. Please enter in exact mode because some numbers are exact integers on purpose (those tend to be shorter when the reals aren't compiled to 2.5-byte pointers into ROM, but not everybody likes to use them because they are also slower). The list of weird numbers between 0 and 1 is precalculated like this: 2. \pi * { 23 28 33 } /
Code:
\<<   DATE DDAYS   { 322 759 462 }   { { 62 258 } { 189 304 453 568 } { 90 370 } }   PICK3 3. NDUPN \->LIST   3. \<< - SWAP MOD EVAL \>> DOLIST   SORT 1. GET   1. + DATE OVER DATE+ UNROT +   { .273181969878 .224399475257 .190399554763 } * SIN   2. ALOG * 0. RND \>>
238.5 bytes, #D5E7h.

And the revised "elegant" program (\^o is the official encoding for the degrees symbol, enter via the units menu or Alpha Rightshift-hold 6):
Code:
\<<   DATE 1. DATE+ DUP UNROT DDAYS   { 322 759 462 }   { { 63 259 } { 190 305 454 569 } { 91 371 } }   PICK3 3. NDUPN \->LIST   3. \<< - SWAP MOD EVAL \>> DOLIST   SORT HEAD   ROT OVER DATE+   "Next extrema date" \->TAG UNROT +   { 23 28 33 } / 360_\^o * SIN   100 * 0. RND   { "P" "E" "I" } \->TAG \>>
310.5 bytes, #EC5Dh.
 « Next Oldest | Next Newest »

 Messages In This Thread HHC 2018 Programming Contests - Joe Horn - 09-13-2018, 02:17 PM RE: HHC 2018 Programming Contests - pier4r - 09-13-2018, 06:29 PM RE: HHC 2018 Programming Contests - Valentin Albillo - 09-13-2018, 10:05 PM RE: HHC 2018 Programming Contests - Zaphod - 09-13-2018, 10:10 PM RE: HHC 2018 Programming Contests - Joe Horn - 09-14-2018, 04:42 AM RE: HHC 2018 Programming Contests - Valentin Albillo - 09-14-2018, 10:28 PM RE: HHC 2018 Programming Contests - toml_12953 - 09-19-2018, 09:57 AM RE: HHC 2018 Programming Contests - Gene - 09-13-2018, 10:56 PM RE: HHC 2018 Programming Contests - rprosperi - 09-13-2018, 11:34 PM RE: HHC 2018 Programming Contests - Gene - 09-14-2018, 12:06 AM RE: HHC 2018 Programming Contests - cyrille de brébisson - 09-14-2018, 05:28 AM RE: HHC 2018 Programming Contests - Joe Horn - 09-14-2018, 06:18 PM RE: HHC 2018 Programming Contests - RMollov - 09-19-2018, 09:42 AM RE: HHC 2018 Programming Contests - Jlouis - 09-19-2018, 07:00 PM RE: HHC 2018 Programming Contests - Thomas Klemm - 09-19-2018, 10:25 AM RE: HHC 2018 Programming Contests - sasa - 09-19-2018, 11:17 AM RE: HHC 2018 Programming Contests - Joe Horn - 09-19-2018, 12:12 PM RE: HHC 2018 Programming Contests - Eddie W. Shore - 09-19-2018, 12:15 PM RE: HHC 2018 Programming Contests - Eddie W. Shore - 09-21-2018, 12:25 PM RE: HHC 2018 Programming Contests - rprosperi - 09-21-2018, 12:53 PM RE: HHC 2018 Programming Contests - Joe Horn - 09-22-2018, 06:59 PM RE: HHC 2018 Programming Contests - Joe Horn - 09-29-2018, 07:03 PM RE: HHC 2018 Programming Contests - pier4r - 09-29-2018, 07:41 PM RE: HHC 2018 Programming Contests - Csaba Tizedes - 09-30-2018, 11:38 AM RE: HHC 2018 Programming Contests - 3298 - 09-30-2018, 05:32 PM RE: HHC 2018 Programming Contests - Csaba Tizedes - 09-30-2018, 07:16 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 09-30-2018, 08:32 PM RE: HHC 2018 Programming Contests - 3298 - 09-30-2018, 08:47 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 09-30-2018, 09:40 PM RE: HHC 2018 Programming Contests - Didier Lachieze - 09-30-2018, 09:54 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 09-30-2018, 10:22 PM RE: HHC 2018 Programming Contests - Gene - 09-29-2018, 07:22 PM RE: HHC 2018 Programming Contests - Joe Horn - 09-30-2018, 04:42 AM RE: HHC 2018 Programming Contests - grsbanks - 09-30-2018, 04:58 AM RE: HHC 2018 Programming Contests - Didier Lachieze - 09-30-2018, 08:49 PM RE: HHC 2018 Programming Contests - Joe Horn - 09-30-2018, 11:24 PM RE: HHC 2018 Programming Contests - Gene - 10-01-2018, 02:55 AM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-01-2018, 05:15 AM RE: HHC 2018 Programming Contests - sasa - 10-01-2018, 05:31 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-01-2018, 06:09 AM RE: HHC 2018 Programming Contests - sasa - 10-01-2018, 09:54 AM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-01-2018, 04:57 AM RE: HHC 2018 Programming Contests - Didier Lachieze - 10-01-2018, 04:59 AM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-01-2018, 06:21 AM RE: HHC 2018 Programming Contests - 3298 - 10-01-2018, 06:37 AM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-03-2018, 04:20 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-01-2018, 06:38 AM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-01-2018, 06:40 AM RE: HHC 2018 Programming Contests - Werner - 10-01-2018, 01:42 PM RE: HHC 2018 Programming Contests - jjohnson873 - 10-01-2018, 08:38 PM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-01-2018, 09:47 PM RE: HHC 2018 Programming Contests - Didier Lachieze - 10-01-2018, 10:46 AM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-01-2018, 09:33 PM RE: HHC 2018 Programming Contests - Werner - 10-02-2018, 06:10 AM RE: HHC 2018 Programming Contests - Fred Lusk - 10-02-2018, 04:15 AM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-02-2018, 08:11 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-02-2018, 04:33 PM RE: HHC 2018 Programming Contests - Eddie W. Shore - 10-03-2018, 12:39 PM RE: HHC 2018 Programming Contests - Namir - 10-04-2018, 06:09 PM RE: HHC 2018 Programming Contests - Joe Horn - 10-02-2018, 08:47 PM RE: HHC 2018 Programming Contests - Werner - 10-03-2018, 02:03 PM RE: HHC 2018 Programming Contests - Didier Lachieze - 10-03-2018, 03:46 PM RE: HHC 2018 Programming Contests - Werner - 10-04-2018, 05:55 AM RE: HHC 2018 Programming Contests - 3298 - 10-04-2018, 02:48 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-04-2018, 03:47 PM RE: HHC 2018 Programming Contests - Joe Horn - 10-05-2018, 12:00 AM RE: HHC 2018 Programming Contests - Didier Lachieze - 10-05-2018, 05:07 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-05-2018, 06:22 AM RE: HHC 2018 Programming Contests - Craig Bladow - 06-25-2019, 01:27 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-05-2018, 12:11 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-05-2018, 12:36 AM RE: HHC 2018 Programming Contests - Didier Lachieze - 10-05-2018, 07:45 AM RE: HHC 2018 Programming Contests - Joe Horn - 10-05-2018, 12:26 PM RE: HHC 2018 Programming Contests - David Hayden - 10-05-2018, 02:25 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-05-2018, 07:23 PM RE: HHC 2018 Programming Contests - 3298 - 10-05-2018, 08:26 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-05-2018, 09:51 PM RE: HHC 2018 Programming Contests - 3298 - 10-06-2018, 12:07 PM RE: HHC 2018 Programming Contests - Joe Horn - 10-05-2018, 09:32 PM RE: HHC 2018 Programming Contests - Eddie W. Shore - 10-06-2018, 03:15 PM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-06-2018, 10:14 AM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-06-2018, 11:42 AM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-06-2018, 12:48 PM RE: HHC 2018 Programming Contests - Gerson W. Barbosa - 10-06-2018, 03:57 PM RE: HHC 2018 Programming Contests - 3298 - 10-06-2018 04:21 PM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-06-2018, 06:38 PM RE: HHC 2018 Programming Contests - David Hayden - 10-07-2018, 01:46 PM RE: HHC 2018 Programming Contests - Thomas Klemm - 10-09-2018, 04:48 AM