Post Reply 
HHC 2018 Programming Contests
10-06-2018, 04:21 PM
Post: #84
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


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 - Zaphod - 09-13-2018, 10:10 PM
RE: HHC 2018 Programming Contests - Gene - 09-13-2018, 10:56 PM
RE: HHC 2018 Programming Contests - Gene - 09-14-2018, 12:06 AM
RE: HHC 2018 Programming Contests - Jlouis - 09-19-2018, 07:00 PM
RE: HHC 2018 Programming Contests - sasa - 09-19-2018, 11:17 AM
RE: HHC 2018 Programming Contests - pier4r - 09-29-2018, 07:41 PM
RE: HHC 2018 Programming Contests - 3298 - 09-30-2018, 05:32 PM
RE: HHC 2018 Programming Contests - 3298 - 09-30-2018, 08:47 PM
RE: HHC 2018 Programming Contests - Gene - 09-29-2018, 07:22 PM
RE: HHC 2018 Programming Contests - Gene - 10-01-2018, 02:55 AM
RE: HHC 2018 Programming Contests - sasa - 10-01-2018, 05:31 AM
RE: HHC 2018 Programming Contests - sasa - 10-01-2018, 09:54 AM
RE: HHC 2018 Programming Contests - 3298 - 10-01-2018, 06:37 AM
RE: HHC 2018 Programming Contests - Werner - 10-01-2018, 01:42 PM
RE: HHC 2018 Programming Contests - Werner - 10-02-2018, 06:10 AM
RE: HHC 2018 Programming Contests - Namir - 10-04-2018, 06:09 PM
RE: HHC 2018 Programming Contests - Werner - 10-03-2018, 02:03 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 - 3298 - 10-05-2018, 08:26 PM
RE: HHC 2018 Programming Contests - 3298 - 10-06-2018, 12:07 PM
RE: HHC 2018 Programming Contests - 3298 - 10-06-2018 04:21 PM



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