Saturday, October 6, 2018

HHC 2018: I Won a Programming Contest! (Biorhythm)

HHC 2018:  I Won a Programming Contest!  (Biorhythm)



Get Our Biorhythms On

In the 1970's, the debunked Biorhythm Theory sought out to measure three facets of our lives beginning at the day of birth:

* Physical: a 23 day cycle
* Emotional: 28 day cycle
* Intellectual: 33 day cycle

The three days start at 0 on the day our birth, then rise and fall between -100 and 100 in sinusoidal waves.  Those waves can be characterized by the following equations:

Physical:  y = 100 * sin (2 * π * x / 23)   (radians)
Emotional: y = 100 * sin (2 * π * x / 28)
Intellectual: y = 100 * sin (2 * π * x / 33)
where x is the number of days from birth. 

The task was to calcuate the next extreme day after the current day.  Here are the details of the contest:  http://hhuc.us/2018/HHC-2018-Programming-Contest.pdf

The thread on the MoHPC forum:  http://www.hpmuseum.org/forum/thread-11390-page-2.html

I entered an HP Prime and won in that category.  Here is the program listing.

HP Prime Program: BIOXTR

sub1(); // elegant background screen

EXPORT BIOXTR()
BEGIN
STARTAPP("Function");
Xmin:=−6*π;Xmax:=6*π;
Ymin:=−1.1;Ymax:=1.1;
sub1();
TEXTOUT("BIORYTHM",−2*π,0,5);
TEXTOUT("by Edward Shore",−2*π,−.5,5);
TEXTOUT("Find your fate.",
−2*π,−2,5);
WAIT(1);

// birthdate
LOCAL b,b1,b2,b3;
INPUT({b1,b2,b3},
"When were you born?",
{"Month: ","Day: ",
"Year: "});
b:=b3+b1/100+b2/10000;

// 
LOCAL d,L0,L1,t,m,p;
d:=DDAYS(b,Date);
L0:={CEILING((d-5.75)/11.5),
CEILING((d-7)/14),
CEILING((d-8.25)/16.5)};
L1:={ROUND(11.5*L0(1)+5.75,0),
ROUND(14*L0(2)+7,0),
ROUND(16.5*L0(3)+8.25,0)};

// loop
WHILE L1(1)≠L1(2) AND L1(1)≠L1(3)
 AND L1(2)≠L1(3) DO
m:=POS(L1,MIN(L1));
L0(m):=L0(m)+1;

L1:={ROUND(11.5*L0(1)+5.75,0),
ROUND(14*L0(2)+7,0),
ROUND(16.5*L0(3)+8.25,0)};
END;

// elegant way to extract the date
IF L1(2)==L1(3) THEN
t:=L1(2);
ELSE
t:=L1(1);
END;
d:=DATEADD(b,t);

// results screen
LOCAL str1;
LOCAL L2:=
{{"Physical: ",23},
{"Emotional: ",28},
{"Intellectual: ",33}};
sub1();
TEXTOUT("Your next extreme day 
is on...",−5*π,1,5);
WAIT(0.5);
str1:=STRING(IP(FP(d)*100))+" / "
+STRING(FP(d*100)*100)+" / "+
STRING(IP(d));
TEXTOUT(str1,−5*π,.6,5);
FOR m FROM 1 TO 3 DO
str1:=L2(m,1)+
STRING(ROUND(100*SIN(2*π*t/
L2(m,2)),0));
TEXTOUT(str1,−5*π,.6-.2*m,5);
END;
WAIT(0);
STARTVIEW(−1);
END;

// screen subroutine
sub1()
BEGIN
RECT(); 
LOCAL t;
HAngle:=0;
FOR t FROM −6*π TO 6*π STEP 12*π/720 DO
PIXON(t,SIN(2*π*t/23),#008000h);
PIXON(t,SIN(2*π*t/28),#FF0000h);
PIXON(t,SIN(2*π*t/33),#0000FFh);
END;
END;



Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...