Biorhythms: Difference between revisions

884 bytes removed ,  11 months ago
→‎{{header|REXX}}: Refurbished and extended (internal (simpler) daysbet2)
m (Minor adjustments to code.)
(→‎{{header|REXX}}: Refurbished and extended (internal (simpler) daysbet2))
Line 2,213:
 
=={{header|REXX}}==
The   '''daysbet2'''   (REXX program) is used   (invoked on line '''3''' of this program)   to calculate the number of days between two dates,
<br>where the dates can be in several formats:
, (a comma) indicates today's date
* (an asterisk) indicates today's date
yyyy-mm-dd where <big><b>yyyy</b></big> may be a 2- or 4-digit year, <big><b>mm</b></big> may be a 1- or 2-digit month, <big><b>dd</b></big> may be a 1- or 2-digit day of month
mm/dd/yyyy (as above)
mm/dd (as above), but the current year is assumed
dd\mm\yyyy (as above)
dd\mm (as above), but the current year is assumed
 
It is usual to use the birth date of a person.
<syntaxhighlight lang="text">/*REXX pgm shows the states of a person's biorhythms (physical, emotional, intellectual) */
parse/* arg birthdate targetDate . /*obtain one or two dates(physical, fromemotional, theintellectual) C.L.*/
days=Parse Arg daysbet2(birthdate targetDate)targetdate . /* obtain one or two dates from CL /*invoke the 2nd version of a REXX pgm.*/
If birthdate='?' Then Do
if days==0 then do; say; say 'The two dates specified are exacty the same.'; exit 1
Say 'rexx bio birthdate (yyyymmdd) shows you today''s biorhythms'
end
Say 'or enter your birthday now'
cycles= 'physical emotional intellectual' /*the names of each biorhythm cycle*/
Parse Pull birthdate
cycle = 'negative neutral positive' /* " states of " " " */
If birthdate='' Then Exit
@.1= 23; @.2= 28; @.3= 33 /* " # of days in " " " */
End
pid2= pi() * 2 * days /*calculate pi * t * number─of─days. */
If birthdate='' Then
Parse Value 19460906 20200906 With birthdate targetdate
If targetdate='' Then
targetdate=Date('S')
days=daysbet2(birthdate,targetdate)
If days==0 Then Do
Say
Say 'The two dates specified are exacty the same.'
Exit 1
End
cycles='physical emotional intellectual' /*the biorhythm cycle names */
cycle='negative neutral positive'
period.1=23
period.2=28
period.3=33
pid2=pi()*2*days
say 'Birthdate: ' birthdate '('translate('gh.ef.abcd',birthdate,'abcdefgh')')'
say 'Today: ' targetdate '('translate('gh.ef.abcd',targetdate,'abcdefgh')')'
Say 'Elapsed days:' days
Do j=1 To 3
state=2+sign(sin(pid2/period.j)) /* obtain state for each biorhythm */
Say 'biorhythm for the' right(word(cycles,j),12) 'cycle is',
word(cycle,state)
End
Exit
/*---------------------------------------------------------------------*/
pi:
pi=3.1415926535897932384626433832795028841971693993751058209749445923078
Return pi
r2r:
Return arg(1)//(pi()*2) /* normalize radians --? a unit ci*/
/*--------------------------------------------------------------------------------------*/
sin: Procedure
Parse Arg x
x=r2r(x)
_=x
Numeric Fuzz min(5,max(1,digits()-3))
If x=pi*.5 Then
Return 1
If x==pi*1.5 Then
Return-1
If abs(x)=pi|x=0 Then
Return 0
q=x*x
z=x
Do k=2 By 2 Until p=z
p=z
_=-_*q/(k*k+k)
z=z+_
End
Return z
 
daysbet2: Procedure
do j=1 for 3
/* compute the number of days between fromdate and todate */
state= 2 + sign( sin( pid2 / @.j) ) /*obtain state for each biorhythm cycle*/
Parse Arg fromdate,todate
say 'biorhythm for the' right(word(cycles,j),12) "cycle is" word(cycle, state)
fromday=date('B',fromdate,'S')
end /*j*/ /* [↑] get state for each biorhythm. */
today=date('B',todate,'S')
exit 0 /*stick a fork in it, we're all done. */
Return today-fromday</syntaxhighlight>
/*──────────────────────────────────────────────────────────────────────────────────────*/
{{out|output|text=&nbsp; when using the default dates}}
pi: pi= 3.1415926535897932384626433832795028841971693993751058209749445923078; return pi
<pre>Birthdate: 19460906 (06.09.1946)
r2r: return arg(1) // (pi() * 2) /*normalize radians ──► a unit circle. */
Today: 20200906 (06.09.2020)
/*──────────────────────────────────────────────────────────────────────────────────────*/
Elapsed days: 27029
sin: procedure; parse arg x; x= r2r(x); _= x; numeric fuzz min(5, max(1, digits() -3))
biorhythm for the physical cycle is positive
if x=pi * .5 then return 1; if x==pi*1.5 then return -1
biorhythm for the emotional cycle is positive
if abs(x)=pi | x=0 then return 0; q= x*x; z= x
biorhythm for the intellectual cycle is positive</pre>
do k=2 by 2 until p=z; p= z; _= -_ *q/(k*k+k); z= z+_; end; return z</syntaxhighlight>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 6/9/1946 </tt>}}
 
Note: &nbsp; today's date is being used, &nbsp; today is the 6<sup>th</sup> of September, 2020.
<pre>
biorhythm for the physical cycle is positive
biorhythm for the emotional cycle is neutral
biorhythm for the intellectual cycle is negative
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'date'
2,295

edits