Biorhythms: Difference between revisions

67,098 bytes added ,  1 month ago
m
(→‎{{header|Raku}}: fix envar default birthday)
 
(47 intermediate revisions by 18 users not shown)
Line 3:
For a while in the late 70s, the pseudoscience of biorhythms was popular enough to rival astrology, with kiosks in malls that would give you your weekly printout. It was also a popular entry in "Things to Do with your Pocket Calculator" lists. You can read up on the history at [https://en.wikipedia.org/wiki/Biorhythm_theory Wikipedia], but the main takeaway is that unlike astrology, the math behind biorhythms is dead simple.
 
It's based on the number of days since your birth. The premise is that three cycles of unspecified provenance govern certain aspects of everyone's lives – specifically, how they're feeling physically, emotionally, and mentally. The best part is that not only do these cycles somehow have the same respective lengths for all humans of any age, gender, weight, genetic background, etc, but those lengths are an exact number of days!. And the pattern is in each case a perfect sine curve. Absolutely miraculous!
 
To compute your biorhythmic profile for a given day, the first thing you need is the number of days between that day and your birth, so the answers in [[Days between dates]] are probably a good starting point. (Strictly speaking, the biorhythms start at 0 at the moment of your birth, so if you know time of day you can narrow things down further, but in general these operate at whole-day granularity.) Then take the residue of that day count modulo each of the the cycle lengths to calculate where the day falls on each of the three sinusoidal journeys.
Line 27:
 
Example run of my Raku implementation:
<langsyntaxhighlight lang="sh">raku br.raku 1943-03-09 1972-07-11</langsyntaxhighlight>
{{Out}}
Line 37:
 
Double valley! This was apparently not a good day for Mr. Fischer to begin a chess tournament...
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">F biorhythms(birthdate_str, targetdate_str)
Print out biorhythm data for targetdate assuming you were
born on birthdate.
 
birthdate and targetdata are strings in this format:
 
YYYY-MM-DD e.g. 1964-12-26
 
print(‘Born: ’birthdate_str‘ Target: ’targetdate_str)
 
V birthdate = time:strptime(birthdate_str, ‘%Y-%m-%d’)
V targetdate = time:strptime(targetdate_str, ‘%Y-%m-%d’)
 
V days = (targetdate - birthdate).days()
 
print(‘Day: ’days)
 
V cycle_labels = [‘Physical’, ‘Emotional’, ‘Mental’]
V cycle_lengths = [23, 28, 33]
V quadrants = [(‘up and rising’, ‘peak’), (‘up but falling’, ‘transition’), (‘down and falling’, ‘valley’), (‘down but rising’, ‘transition’)]
 
L(i) 3
V label = cycle_labels[i]
V length = cycle_lengths[i]
V position = days % length
V quadrant = Int(floor((4 * position) / length))
V percentage = Int(round(100 * sin(2 * math:pi * position / length), 0))
V transition_date = (targetdate + TimeDelta(days' floor((quadrant + 1) / 4 * length) - position)).strftime(‘%Y-%m-%d’)
V (trend, next) = quadrants[quadrant]
 
String description
I percentage > 95
description = ‘peak’
E I percentage < -95
description = ‘valley’
E I abs(percentage) < 5
description = ‘critical transition’
E
description = percentage‘% (’trend‘, next ’next‘ ’transition_date‘)’
print(label‘ day ’position‘: ’description)
 
biorhythms(‘2043-03-09’, ‘2072-07-11’)</syntaxhighlight>
 
{{out}}
<pre>
Born: 2043-03-09 Target: 2072-07-11
Day: 10717
Physical day 22: -27% (down but rising, next transition 2072-07-12)
Emotional day 21: valley
Mental day 25: valley
</pre>
 
=={{header|Amazing Hopper}}==
<p>Esta es mi versión de la tarea: en vez de mostrar cifras frías, es mejor un gráfico, aunque este sea en texto.</p>
<p>Hopper permite usar la opción de preprocesamiento especial "High level", que consiste en que todo lo encerrado entre "#( )" será escrito de la forma infija formal, con expresiones como "(2+3)*sin(PI)" y cosas parecidas. En la tarea presente, la cantidad de cálculos y su complejidad hacen meritorio usar esta opción del preprocesador, que no es muy óptima debido a que realiza un preprocesado general, pero salva.</p>
<p>Un preprocesamiento general hace que una línea como "a+b" sea convertida a "{a};{b};add", cuando lo óptimo sería "{a} plus(b)", porque en el segundo caso no es necesario pasar "b" a la pila de trabajo. la instrucción "plus" no trabaja con expresiones.</p>
<p>Las expresiones dentro de "#()" deben escribirse cuidando el uso de paréntesis y sin espacios en blanco en los nombres de variables.</p>
 
<syntaxhighlight lang="Amazing Hopper">
/* TASK: Bioritmo, Rosetta Code */
 
#include <jambo.h>
 
Main
Set break
Set stack 15
Get total args
If ( Is equal to '7' )
/* argumentos del programa*/
 
nombre="", año=0, mes=0, día=0, año a examinar=0, mes a examinar=0
Set ' Arg str(2), Arg num(3) Arg num(4), Arg num(5) ', Move to 'nombre, año, mes, día'
Set ' Arg num(6), Arg num(7) ', Move to 'mes a examinar, año a examinar'
 
/* arrays de valores constantes */
Void ' Etiquetas, Meses, Factores '
/* otras variables utilitarias */
b=año, g=año a examinar, l=g, r=0
 
/* programa */
Gosub 'Configuración del programa'
Gosub 'Construcción del bioritmo'
Locate (22, 1), Prnl
Else
Printnl ("Modo de uso: hopper bioritmo.jambo NOMBRE DD MM AA MME AAE")
Printnl (Utf8("donde DD,MM,AA fecha de nacimiento, MME, AAE mes y año a examinar"))
End If
End
 
Subrutines
 
Define 'Construcción del bioritmo'
ak=0, b1=0, y=0
Loop
Gosub 'Análisis de año bisiesto'
Let ( ak := #( Factores[mes]+28.5-día ) )
++mes
x=12
When ( #( mes < 13 ) ){ Set 'ak,x', Let( ak := Gosub 'Cálculo' ) }
Let ( b1 := #( g-b-1 ) )
Set decimal '0'
Let ( ak := #( (b1*365+((g-1)/4)-((g-1)/100)+((g-1)/400)-((b/4)-(b/100)+(b/400))+ak) ) )
Unset decimal
y = ak
Let (b := g)
Gosub 'Análisis de año bisiesto'
 
Let ( x := #( mesaexaminar - 1 ) )
Let ( mes := 1 )
If ( #( x <> 0 ) )
Set 'ak, x', Let( ak := Gosub 'Cálculo' )
y = ak
End If
 
Cls
Set 'ak, y', Gosub 'Desplegar la malla'
Pause
++mes a examinar
Until ( #( mesaexaminar == 13 ) )
Return
 
Define 'Desplegar la malla, ak, y'
i=4, j=0, i1=1, fi=3
 
Loop
Set 'i, i1, fi', Gosub 'Genera la malla'
Set 'i, fi, i1', Gosub 'Escribe la identificación'
Set 'ak, i, fi', Gosub 'Despliega el bioritmo'
i += 34
Let ( ak := y )
++i1
++j
Until ( #( j == 3 ) )
 
Return
 
Define 'Genera la malla, i, i1, fi'
j1=4, j2=0, ti=i, i2=0
 
Let ( r := Get if( Equals( i1,1 ), 23, Get if( Equals( i1,2 ), 28, 33) ) )
 
Loop
Let ( j2 := Add( 4, i ) )
 
Loop if ( #( j2 < ( (27+Factores[mesaexaminar])+i) ) )
Locate ( #(j1+fi), j2 ), Printnl (" |")
j2 += 5
Back
 
Locate ( #(j1+fi), #( 28+(Factores[mesaexaminar])+i) ), Printnl ("| ")
++j1
Until ( #( j1 > 13 ) )
 
Let ( i := ti )
i2 = ti
j2 = 1
Loop if ( #( j2 < ((27 + Factores[mesaexaminar] )+1) ) )
Locate ( #(8+fi), #(i2+1) ), Printnl ("-")
++i2, ++j2
Back
 
Locate ( #(8+fi), #(5+i) ), Printnl ( "+" )
Loccol ( #(10+i) ), Printnl ( "+" )
Loccol ( #(15+i) ), Printnl ( "+" )
Loccol ( #(20+i) ), Printnl ( "+" )
Loccol ( #(25+i) ), Printnl ( "+" )
 
Locate ( #(14+fi), #(1+i) ), Printnl ( "1...5...10...15...20...25..." )
 
If ( #( (28+Factores[mesaexaminar]) == 29 ) )
Locate ( #(14+fi), #(29+i) ), Printnl ( "." )
Else If ( #( (28+ Factores[mesaexaminar]) == 30 ) )
Locate ( #(14+fi), #(29+i) ), Printnl ( "30" )
Locate ( #(8+fi), #(30+i) ), Printnl ( "+" )
Else If ( #( (28+Factores[mesaexaminar]) == 31 ) )
Locate ( #(14+fi), #(29+i) ), Printnl ( "30." )
Locate ( #(8+fi), #(30+i) ), Printnl ( "+" )
End If
 
Return
 
Define 'Escribe la identificación, i, fi, i1'
Locate ( #(16+fi), #(1+i) ), Printnl ( #( Meses[mesaexaminar] ), " ", Int(l), " D. de C." )
Locrow ( #(17+fi) ), Printnl ( "Bioritmo para ", nombre )
Locrow ( #(18+fi) ), Printnl ( "Estado: ", #( Etiquetas[i1] ) )
Return
 
Define 'Despliega el bioritmo, ak, i, fi'
n=0, j=0
PI = M_PI
 
Loop if( #( j < ( (28 + Factores[mesaexaminar]) * 2 ) ) )
Let ( ak := #( ak + 0.5 ) )
Let ( n := #( (10 * ( -(sin( ( 2 * PI * ak ) / r ) ) ) ) + 17 ) )
 
If ( #( (int( int( j / 2 )-(( int( j / 2) / 5) * 5))) == 5 ) )
Locate ( #( int( n / 2 ) + fi ), #( int( j / 2 ) + ( i + 1 )) )
Else
Locate ( #( (n / 2 ) + fi ), #( ( j / 2 ) + ( i + 1 ) ) )
End If
Printnl ("*")
++j
Back
 
Return
 
Define 'Análisis de año bisiesto'
x1=0, x2=0, x3=0
/* "b" es variable global */
Let ( x1 := Get if ( #( b - ( int( b / 4 ) * 4 ) == 0 ), 1, 0 ))
Let ( x2 := Get if ( #( b - ( int( b / 100 ) * 100 ) == 0 ), 1, 0 ))
Let ( x3 := Get if ( #( b - ( int( b / 400 ) * 400 ) == 0 ), 1, 0 ))
[2] #( x1 - x2 + x3 ), Put 'Factores'
Return
 
Define 'Cálculo, ak,x'
i = mes
Loop if( #(i <= x) )
Let ( ak := #( 28 + Factores[i] + ak ) )
++i
Back
Return 'ak'
 
/* CONFIGURACION DEL PROGRAMA */
 
Define ' Configuración del programa '
Set ' Utf8("Físico"), "Emocional", "Intelectual" ' Apnd list 'Etiquetas'
Set ' "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", \
"Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" ' Apnd list 'Meses'
Set ' 3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3 ' Apnd list 'Factores'
Return
</syntaxhighlight>
{{out}}
<pre>
$ hopper jm/bioritmo.jambo
Modo de uso: hopper bioritmo.jambo NOMBRE DD MM AA MME AAE
donde DD,MM,AA fecha de nacimiento, MME, AAE mes y año a examinar
 
$ hopper jm/bioritmo.jambo Mr.Dalien 18 1 1980 1 2022
*** ** ***** ****
| ** ** | | || **| | | | ** |* ** | | | | |*
| ** |** | | || ** | | | *| || |** | | | | **|
| *| | * | | || ** | | | * | || | ** | | | | **||
| * | | * | | |* |** | | | * | || | **| | | | ** ||
----+-*--+----+---*+----+----*| ----+-*--+----+----+*---+----+| ----+---**----+----+----+**--+|
|** | | ** | **| | * | | ** | || | |* | | * ||
|* | | * | *|| | *| | ** | || | | * | | *| ||
* | | |* | * || | * | **| | || | | **| | ** | ||
**| | | | ** |** || | |** | ** | | || | | ** |** | ||
*** | | | | **** || | | ***** | | || | | |***** | ||
1...5...10...15...20...25...30. 1...5...10...15...20...25...30. 1...5...10...15...20...25...30.
 
Enero 2022 D. de C. Enero 2022 D. de C. Enero 2022 D. de C.
Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien
Estado: Físico Estado: Emocional Estado: Intelectual
 
 
*** ** ***** ******
** | ** | | | ** | * | | | | ** | * * |** | | | | |
** | **| | | ** | ** | | | |* | | | **| | | | |
* | *| | | *| | ** | | | * | | | ** | | | |
| * | | * | | **| | | *| | | | ** | | | |
----+----+*---+----+-*--+--| ---*+----+----+--*-+----+--| ----+----+**--+----+----+--*
| |** | |** | | * | | ** | | | | | * | | | *|
| | * | |* | | |* | |** | | | | | *| | |* |
| | * | * | | | * | ** | | | | | ** | ** |
| | ** **| | | | **| ** | | | | | |** | **| |
| | **** | | | | ***** | | | | | | | ***** | |
1...5...10...15...20...25... 1...5...10...15...20...25... 1...5...10...15...20...25...
 
Febrero 2022 D. de C. Febrero 2022 D. de C. Febrero 2022 D. de C.
Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien
Estado: Físico Estado: Emocional Estado: Intelectual
 
....
*** ** ***** ******
** ** | | | **|| | | | ** | **| || | ** |** | | ||
** |** | | | ** || | | |* | ** || | **| | **| | ||
*| | * | | | * || | | * | ** || | ** | | ** | ||
* | | * | | |* || | | *| | |** || |** | | ** | ||
-*--+----+---*+----+----*----+| ----+----+--*-+----+----+-*--+| ----**---+----+----+**--+----+|
** | | ** | ** || | | ** | | | * || *| | | | * | ||
* | | * | *| || * | |** | | | *|| * | | | | *| ||
| | |* | * | || * | ** | | | *| ** | | | | ** ||
| | | ** |** | || **| ** | | | |* * | | | | |** ||
| | | **** | || ***** | | | | || | | | | | ****
1...5...10...15...20...25...30. 1...5...10...15...20...25...30. 1...5...10...15...20...25...30.
 
Mayo 2022 D. de C. Mayo 2022 D. de C. Mayo 2022 D. de C.
Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien
Estado: Físico Estado: Emocional Estado: Intelectual
 
....
 
*** * ***** * ******
** ** | | | **| ** | ** | | | | ** | | | | ** *
** |** | | | ** | | **| | | | * | | | | | ** | |
*| | * | | | * | | ** | | | * | * | | | |** | |
* | | * | | |* | | ** | | |* | ** | | | ** | |
-*--+----+---*+----+----*----+ ----+----+*---+----+----*----+ -**-+----+----+---**----+----+
** | | ** | ** | | | * | | ** | *| | | * | | |
* | | * | *| | | | * | | **| | * | | * | | |
| | |* | * | | | | *| | ** | | |** | ** | | |
| | | ** |** | | | | ** |** | | | ** | ** | | |
| | | **** | | | | |***** | | | ***** | | | |
1...5...10...15...20...25...30 1...5...10...15...20...25...30 1...5...10...15...20...25...30
 
Noviembre 2022 D. de C. Noviembre 2022 D. de C. Noviembre 2022 D. de C.
Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien
Estado: Físico Estado: Emocional Estado: Intelectual
 
 
** *** **** **** ****
**| | | |** |** || ** | | | | ** || * | | | | | ** ||
** | | ** | ** || |** | | | |* || ** | | | | ** ||
* | | * | * || | ** | | | * || **| | | | ** ||
|* | | *| | *|| | **| | | *| || ** | | | **| ||
----+-*--+----+--*-+----+----*| ----+---*+----+----+--*-+----+| ----**---+----+----+-**-+----+|
| ** | | ** | | ** | * | | ** | || | * | | |* | ||
| * | | * | | |* | |* | |** | || | * | | * | ||
| *| |* | | || | | * | ** | || | ** | **| | ||
| ** ** | | || | | **| ** | || | ** | ** | | ||
| |****| | | || | | ***** | | || | | ***** | | ||
1...5...10...15...20...25...30. 1...5...10...15...20...25...30. 1...5...10...15...20...25...30.
 
Diciembre 2022 D. de C. Diciembre 2022 D. de C. Diciembre 2022 D. de C.
Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien Bioritmo para Mr.Dalien
Estado: Físico Estado: Emocional Estado: Intelectual
 
</pre>
 
=={{header|C}}==
{{trans|Locomotive Basic}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int day(int y, int m, int d) {
return 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d - 730530;
}
 
void cycle(int diff, int l, char *t) {
int p = round(100 * sin(2 * M_PI * diff / l));
printf("%12s cycle: %3i%%", t, p);
if (abs(p) < 15)
printf(" (critical day)");
printf("\n");
}
 
int main(int argc, char *argv[]) {
int diff;
 
if (argc < 7) {
printf("Usage:\n");
printf("cbio y1 m1 d1 y2 m2 d2\n");
exit(1);
}
diff = abs(day(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]))
- day(atoi(argv[4]), atoi(argv[5]), atoi(argv[6])));
printf("Age: %u days\n", diff);
cycle(diff, 23, "Physical");
cycle(diff, 28, "Emotional");
cycle(diff, 33, "Intellectual");
}</syntaxhighlight>
Test:
<syntaxhighlight lang="bash">gcc -o cbio cbio.c -lm
./cbio 1972 7 11 1943 3 9
Age: 10717 days
Physical cycle: -27%
Emotional cycle: -100%</syntaxhighlight>
Intellectual cycle: -100%</syntaxhighlight>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <chrono>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <numbers>
#include <sstream>
#include <string>
#include <vector>
 
const double tau = 2 * std::numbers::pi;
const std::vector<std::string> cycles { "PHYSICAL", "EMOTIONAL", "MENTAL" };
const std::vector<std::int32_t> cycle_lengths { 23, 28, 33 };
const std::vector<std::vector<std::string>> descriptions { { "up and rising", "peak" },
{ "up but falling", "transition" },
{ "down and falling", "valley" },
{ "down but rising", "transition" } };
 
std::string to_string(const std::chrono::sys_days& sys_date) {
std::stringstream stream;
stream << sys_date;
std::string iso_date;
stream >> iso_date;
return iso_date;
}
 
std::chrono::sys_days create_date(const std::string& iso_date) {
const int year = std::stoi(iso_date.substr(0, 4));
const unsigned int month = std::stoi(iso_date.substr(5, 7));
const unsigned int day = std::stoi(iso_date.substr(8, 10));
 
std::chrono::year_month_day date{std::chrono::year{year}, std::chrono::month{month}, std::chrono::day{day}};
return std::chrono::sys_days(date);
}
 
void biorhythms(const std::vector<std::string>& date_pair) {
std::chrono::sys_days birth_date = create_date(date_pair[0]);
std::chrono::sys_days target_date = create_date(date_pair[1]);
int32_t days_between = ( target_date - birth_date ).count();
std::cout << "Birth date " << birth_date << ", Target date " << target_date << std::endl;
std::cout << "Days between: " << days_between << std::endl;
 
for ( int32_t i = 0; i < 3; ++i ) {
const int32_t cycle_length = cycle_lengths[i];
const int32_t position_in_cycle = days_between % cycle_length;
const int32_t quadrant_index = 4 * position_in_cycle / cycle_length;
const int32_t percentage = round(100 * sin(tau * position_in_cycle / cycle_length));
 
std::string description;
if ( percentage > 95 ) {
description = "peak";
} else if ( percentage < -95 ) {
description = "valley";
} else if ( abs(percentage) < 5 ) {
description = "critical transition";
} else {
const int32_t days_to_transition = ( cycle_length * ( quadrant_index + 1 ) / 4 ) - position_in_cycle;
std::chrono::sys_days transition_date = target_date + std::chrono::days{days_to_transition};
std::string trend = descriptions[quadrant_index][0];
std::string next_transition = descriptions[quadrant_index][1];
description = std::to_string(percentage) + "% (" + trend + ", next " + next_transition
+ " " + to_string(transition_date) + ")";
}
 
std::cout << cycles[i] << " day " << position_in_cycle << ": " << description << std::endl;
}
std::cout << std::endl;
}
 
int main() {
const std::vector<std::vector<std::string>> date_pairs = {
{ "1943-03-09", "1972-07-11" },
{ "1809-01-12", "1863-11-19" },
{ "1809-02-12", "1863-11-19" } };
 
for ( const std::vector<std::string>& date_pair : date_pairs ) {
biorhythms(date_pair);
}
}
</syntaxhighlight>
{{ out }}
<pre>
Birth date 1943-03-09, Target date 1972-07-11
Days between: 10717
PHYSICAL day 22: -27% (down but rising, next transition 1972-07-12)
EMOTIONAL day 21: valley
MENTAL day 25: valley
 
Birth date 1809-01-12, Target date 1863-11-19
Days between: 20034
PHYSICAL day 1: 27% (up and rising, next peak 1863-11-23)
EMOTIONAL day 14: critical transition
MENTAL day 3: 54% (up and rising, next peak 1863-11-24)
 
Birth date 1809-02-12, Target date 1863-11-19
Days between: 20003
PHYSICAL day 16: -94% (down and falling, next valley 1863-11-20)
EMOTIONAL day 11: 62% (up but falling, next transition 1863-11-22)
MENTAL day 5: 81% (up and rising, next peak 1863-11-22)
</pre>
 
=={{header|COBOL}}==
{{trans|Locomotive Basic}}
<syntaxhighlight lang="cobol">
 
identification division.
program-id. bio.
environment division.
*************************************************************
**** To execute on command line enter program name followed
**** by birth date ccyymmdd and then target date.
**** Example: bio 18090102 18631117
**** Will display the three cycles:
**** Physcial 23 days, Emotional 28 days, Mental 33 days
**** for that date.
****
*************************************************************
configuration section.
source-computer.
System76
* with debugging mode
.
repository.
function all intrinsic.
 
data division.
working-storage section.
01 w-d1 pic x(08).
01 w-d2 pic x(08).
01 n-d1 pic 9(08).
01 n-d2 pic 9(08).
01 w-i1 comp-x pic x(04).
01 w-i2 comp-x pic x(04).
01 w-days pic 9(07).
01 arg-knt comp-5 pic x(01).
01 bx pic 9.
01 bio-tbl value 'Physical 23Emotional28Mental 33'.
05 bio-entry occurs 3 times.
10 bio-cyc pic x(09).
10 bio-lth pic 9(02).
01 bio-data occurs 3 times.
05 bio-mod pic 9(02).
05 bio-sin pic s999v9.
05 bio-dsc pic x(09).
 
procedure division.
accept arg-knt from argument-number
if arg-knt <> 2
then
display 'two arguments are required:' upon SYSERR
display ' 1. first date ccyymmdd' upon SYSERR
display ' 2. second date ccyymmdd' upon SYSERR
stop run returning -1
end-if
accept w-d1 from argument-value
if w-d1 not numeric
display ' first date not numeric ' upon syserr
move 2 to return-code
stop run
end-if
move w-d1 to n-d1
if (n-d1 > 99991231)
display ' first date must be less than 99991232'
upon syserr
move 3 to return-code
stop run
end-if
if (n-d1 < 16010101)
display ' first date must be greater than 16010100'
upon syserr
move 4 to return-code
stop run
end-if
if ((n-d1(5:2) = '00')
or
(n-d1(5:2) > '12'))
display ' invalid month for first date ' upon syserr
move 5 to return-code
stop run
end-if
if ((n-d1(7:2) = '00')
or
(n-d1(7:2) > '31'))
display ' invalid day for first date ' upon syserr
move 6 to return-code
stop run
end-if
accept w-d2 from argument-value
if w-d2 not numeric
display 'second date not numeric ' upon syserr
move 12 to return-code
stop run
end-if
move w-d2 to n-d2
if (n-d2 > 99991231)
display ' second date must be less than 99991232'
upon syserr
move 13 to return-code
stop run
end-if
if (n-d2 < 16010101)
display ' second date must be greater than 16010100'
upon syserr
move 14 to return-code
stop run
end-if
if ((n-d2(5:2) = '00')
or
(n-d2(5:2) > '12'))
display ' invalid month for second date ' upon syserr
move 15 to return-code
stop run
end-if
if ((n-d2(7:2) = '00')
or
(n-d2(7:2) > '31'))
display ' invalid day for second date ' upon syserr
move 16 to return-code
stop run
end-if
move w-d1 to n-d1
move w-d2 to n-d2
move integer-of-date(n-d1) to w-i1
move integer-of-date(n-d2) to w-i2
compute w-days = w-i1 - w-i2
display w-days
perform varying bx from 1 by 1 until bx greater than 3
move mod(w-days, bio-lth(bx)) to bio-mod(bx)
compute bio-sin(bx) rounded
= 100 * sin(2 * PI * bio-mod(bx) / bio-lth(bx))
end-compute
display bio-cyc(bx) " "
bio-mod(bx) ":"
bio-sin(bx) "%" with no advancing
end-display
if bio-sin(bx) > 95
move " peak" to bio-dsc(bx)
end-if
if bio-sin(bx) < -95
move " valley" to bio-dsc(bx)
end-if
if abs(bio-sin(bx)) < 5
move " critical" to bio-dsc(bx)
end-if
display bio-dsc(bx)
end-perform
move 0 to return-code
goback
.
 
</syntaxhighlight>
Test:
<syntaxhighlight lang="bash">
Compile and Test
C:\GnuCOBOL>
C:\GnuCOBOL>cobc -x bio.cbl
 
C:\GnuCOBOL>bio 18090112 18631119
0020034
Physical 01:+027.0%
Emotional 14:+000.0% critical
Mental 03:+054.1%</syntaxhighlight>
=={{header|Common Lisp}}==
{{trans|Locomotive Basic}}
<syntaxhighlight lang="lisp">;;;; Common Lisp biorhythms
 
;;; Get the days to J2000
;;; FNday only works between 1901 to 2099 - see Meeus chapter 7
 
(defun day (y m d)
(+ (truncate (* -7 (+ y (truncate (+ m 9) 12))) 4)
(truncate (* 275 m) 9) d -730530 (* 367 y)))
 
;;; Get the difference in days between two dates
 
(defun diffday (y1 m1 d1 y2 m2 d2)
(abs (- (day y2 m2 d2) (day y1 m1 d1))))
 
;;; Print state of a single cycle
 
(defun print-cycle (diff len nm)
(let ((perc (round (* 100 (sin (* 2 pi diff (/ 1 len)))))))
(format t "~A cycle: ~D% " nm perc)
(if (< (abs perc) 15)
(format t "(critical)~%")
(format t "~%"))))
 
;;; Print all cycles
 
(defun print-bio (y1 m1 d1 y2 m2 d2)
(let ((diff (diffday y1 m1 d1 y2 m2 d2)))
(format t "Age in days: ~D ~%" diff)
(print-cycle diff 23 "physical")
(print-cycle diff 28 "emotional")
(print-cycle diff 33 "intellectual")))</syntaxhighlight>
{{output}}
<pre>* (print-bio 1972 7 11 1943 3 9)
Age in days: 10717
physical cycle: -27%
emotional cycle: -100%
intellectual cycle: -100% </pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.Math}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Biorhythms;
 
Line 146 ⟶ 836:
CalcBiorhythms(datePairs[i, 0], datePairs[i, 1]);
readln;
end.</langsyntaxhighlight>
=={{header|EasyLang}}==
 
[https://easylang.online/show/#cod=bVNNj6MwDL3nVzwxaNUpgnX4aMuB4x72tn+hkIwaCUgFYabsr185QNtZ9ULs9+zYfia1GdwlRIVAlnkWUxZTGQh1dnoFj2lMx1jKQLxhg8epHt0AZzrN5ziPbEJCkniD+Jj6Buo8Q4VIBIAZFfqpq/WwpaoQEjlz3SvugJQ59YorF27Qbhp6ZIcj9pgRg8/djAi7DhHKdyjzCZkuZ44I6bHAHp33S0RQnJRRkZFIhNM3N5q/GvnSvumNQx3eR2hNr7+MchdQ4ut39lOjINDGsiOJ7hyheHCSNvfDDn6uOCU4i9SDW85tDQLQmKFpNSgpVuCGqEK6uMm9So7Sy8j9ow6f8NPpjiuPq/M8oloW4xcZe7v2f8BzIj0SOeUHAm8ET7KzLxJxHWyDZuZGe/vFFlyIxrZIlh4b29qBv0/3c9QeMkkRr+P7Wi78X+fiWS++n+NZNLajh3RXVEzsMZoeu+zApsJPLvS+hvglsLqIcH0paCJWfZbNL8/C6ySWAT2dZgj+XObRNOc2QEn0jTwh+NVZZ2zPLJXf2CxD8Lt3um114yYfQKUQ/wA= Run it]
 
<syntaxhighlight>
birth$ = "1943-03-09"
date$ = "1972-07-11"
# date$ = substr timestr systime 1 10
#
func day d$ .
y = number substr d$ 1 4
m = number substr d$ 6 2
d = number substr d$ 9 2
return 367 * y - 7 * (y + (m + 9) div 12) div 4 + 275 * m div 9 + d - 730530
.
textsize 4
func init b$ d$ .
linewidth 0.2
move 50 0
line 50 100
move 0 50
line 100 50
for d = -20 to 20
move x 50
circle 0.5
x += 2.5
.
move 4 94
text b$
move 4 88
text d$
days = day date$ - day birth$
move 4 80
text days & " days"
return days
.
proc cycle now cyc t$ col . .
color col
move 4 cyc * 1.2 - 20
text t$
linewidth 0.5
for d = now - 20 to now + 20
p = 20 * sin (360 * d / cyc)
line x 50 + p
x += 2.5
.
.
days = init birth$ date$
cycle days 23 "Physical" 900
cycle days 28 "Emotional" 090
cycle days 33 "Intellectual" 009
</syntaxhighlight>
 
=={{header|Emacs Lisp}}==
For Emacs, it makes sense to implement this as an interactive command which is personalized to the user's birthdate and computes the biorhythm for today. So if you put this code into your .emacs file (note that the birthdate has to be in MDY order in Emacs!):
<syntaxhighlight lang="lisp">(require 'calendar)
 
(setq biorhythm-birthdate '(3 16 1953))
 
(defun biorhythm ()
"Show today's biorhythm."
(interactive)
(let* ((diff (abs (- (string-to-number (calendar-astro-date-string
biorhythm-birthdate)) (string-to-number
(calendar-astro-date-string)))))
(rhyt '(23 28 33))
(perc (mapcar (lambda (x) (round (* 100 (sin
(* 2 pi diff (/ 1.0 x)))))) rhyt)))
(message "age: %i physical: %i%% emotional: %i%% intellectual: %i%%"
diff (car perc) (cadr perc) (caddr perc))))</syntaxhighlight>
Then typing "M-x biorhythm" will produce this output in the Emacs echo area on 2022-04-21:
<pre>
age: 25238 physical: 94% emotional: 78% intellectual: -97%
</pre>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: calendar calendar.parser formatting io kernel math
math.constants math.functions ;
 
Line 169 ⟶ 934:
[ 33 "Mental" .day ] tri ;
 
"1809-02-12" "1863-11-19" .biorhythm</langsyntaxhighlight>
{{out}}
<pre>
Line 178 ⟶ 943:
Mental day 5: 81.5%↑
</pre>
=={{header|FOCAL}}==
{{trans|Locomotive Basic}}
<syntaxhighlight lang="focal">1.01 T "Enter birthdate (y,m,d)",!
1.02 ASK Y,M,D
1.03 D 2; S BZ=Z
1.04 T "Enter today's date (y,m,d)",!
1.05 ASK Y,M,D
1.06 D 2; S DI=Z - BZ
1.07 T %6,"Age in days", DI,!
1.08 T "Physical cycle: "
1.09 S L=23; D 3
1.10 T "Emotional cycle: "
1.11 S L=28; D 3
1.12 T "Intellectual cycle: "
1.13 S L=33; D 3
1.14 Q
 
2.1 S QA = FITR((M + 9) / 12)
2.2 S QB = FITR(275 * M / 9)
2.3 S QC = FITR(7 * (Y + QA) / 4)
2.4 S Z = 367 * Y - QC + QB + D - 730530
 
3.1 S P = 100 * FSIN(2*3.1415926536*DI/L)
3.2 T %3,P,"%"
3.3 I (FABS(P)-15)4.1,5.1,5.1
 
4.1 T " CRITICAL",!
 
5.1 T !</syntaxhighlight>
{{output}}
<pre>*G
Enter birthdate (y,m,d)
:1943,:3,:9
Enter today's date (y,m,d)
:1972,:7,:11
Age in days= 10717
Physical cycle: =- 27%
Emotional cycle: =-100%
Intellectual cycle: =-100%</pre>
=={{header|Fortran}}==
 
Line 184 ⟶ 987:
 
 
<langsyntaxhighlight Fortranlang="fortran">C ------------------------------------------------------------------
PROGRAM BIORHYTHM
C ------------------------------------------------------------------
Line 355 ⟶ 1,158:
RETURN
END</langsyntaxhighlight>
 
{{in}}
Line 412 ⟶ 1,215:
E P : | M : | THR 84
===========================================================================</pre>
=={{header|FreeBASIC}}==
{{trans|VBA}}
<syntaxhighlight lang="freebasic">#define floor(x) ((x*2.0-0.5) Shr 1)
#define pi (4 * Atn(1))
 
Function Gregorian(db As String) As Integer
Dim As Integer M, Y, D
Y = Valint(Left(db,4)) : M = Valint(Mid(db,6,2)) : D = Valint(Right(db,2))
Dim As Integer N = (M+9) - Int((M+9)/12) * 12
Dim As Integer W = Y - Int(N/10)
Dim As Integer G = 365 * W + Int(W/4) - Int(W/100) + Int(W/400)
G += Int((N*306+5)/10)+(D-1)
Return G
End Function
 
Function Biorhythm(Birthdate As String, Targetdate As String) As String
'Jagged Array
Dim As String TextArray(4,2) = {{"up and rising", "peak"}, {"up but falling", "transition"}, {"down and falling", "valley"}, {"down but rising", "transition"}}
Dim As Integer DaysBetween = Gregorian(Targetdate) - Gregorian(Birthdate)
Dim As Integer positionP = DaysBetween Mod 23
Dim As Integer positionE = DaysBetween Mod 28
Dim As Integer positionM = DaysBetween Mod 33
'return the positions - just to return something
Biorhythm = Str(positionP) & "/" & Str(positionE) & "/" & Str(positionM)
Dim As Integer quadrantP = Int(4 * positionP / 23)
Dim As Integer quadrantE = Int(4 * positionE / 28)
Dim As Integer quadrantM = Int(4 * positionM / 33)
Dim As Single percentageP = Fix(100 * Sin(2 * pi * (positionP / 23)))
Dim As Single percentageE = Fix(100 * Sin(2 * pi * (positionE / 28)))
Dim As Single percentageM = Fix(100 * Sin(2 * pi * (positionM / 33)))
Dim As Single transitionP = Val(Targetdate) + floor((quadrantP + 1) / 4 * 23) - positionP
Dim As Single transitionE = Val(Targetdate) + floor((quadrantE + 1) / 4 * 28) - positionE
Dim As Single transitionM = Val(Targetdate) + floor((quadrantM + 1) / 4 * 33) - positionM
Dim As String textP, textE, textM, Header1Text, Header2Text
Select Case percentageP
Case Is > 95
textP = "Physical day " & positionP & " : " & "peak"
Case Is < -95
textP = "Physical day " & positionP & " : " & "valley"
Case -5 To 5
textP = "Physical day " & positionP & " : " & "critical transition"
Case Else
textP = "Physical day " & positionP & " : " & percentageP & "% (" & TextArray(quadrantP,0) & ", next " & TextArray(quadrantP,1) & " " & transitionP & ")"
End Select
Select Case percentageE
Case Is > 95
textE = "Emotional day " & positionE & " : " & "peak"
Case Is < -95
textE = "Emotional day " & positionE & " : " & "valley"
Case -5 To 5
textE = "Emotional day " & positionE & " : " & "critical transition"
Case Else
textE = "Emotional day " & positionE & " : " & percentageE & "% (" & TextArray(quadrantE,0) & ", next " & TextArray(quadrantE,1) & " " & transitionE & ")"
End Select
Select Case percentageM
Case Is > 95
textM = "Mental day " & positionM & " : " & "peak"
Case Is < -95
textM = "Mental day " & positionM & " : " & "valley"
Case -5 To 5
textM = "Mental day " & positionM & " : " & "critical transition"
Case Else
textM = "Mental day " & positionM & " : " & percentageM & "% (" & TextArray(quadrantM,0) & ", next " & TextArray(quadrantM,1) & " " & transitionM & ")"
End Select
Header1Text = "Born " & Birthdate & ", Target " & Targetdate
Header2Text = "Day " & DaysBetween
Print Header1Text
Print Header2Text
Print textP
Print textE
Print textM
Print
End Function
 
Biorhythm("1943-03-09", "1972-07-11")
 
Biorhythm("1809-02-12", "1863-11-19") 'correct DOB for Abraham Lincoln
Biorhythm("1809-01-12", "1863-11-19")
</syntaxhighlight>
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 489 ⟶ 1,377:
biorhythms(datePair[0], datePair[1])
}
}</langsyntaxhighlight>
 
{{out}}
Line 511 ⟶ 1,399:
Mental day 5 : 81.4% (up and rising, next peak 1863-11-22)
</pre>
 
=={{header|J}}==
Let's presume the content of file <tt>br.ijs</tt> :
<syntaxhighlight lang="j">
<lang J>
use=: 'Use: ', (;:inv 2 {. ARGV) , ' YYYY-MM-DD YYYY-MM-DD'
 
Line 535 ⟶ 1,422:
 
exit 0
</syntaxhighlight>
</lang>
Then bash commands could be
<pre>
Line 550 ⟶ 1,437:
│Mental │ _0.9 _0.9 _1.0 _1.0 _1.0 _0.9 _0.8│ 0.9 0.9 1.0 1.0 1.0 0.9 0.8│
└──────────┴──────────────────────────────────────────┴──────────────────────────────────────────┘
</pre>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
 
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.List;
 
public final class Biorythms {
 
public static void main(String[] aArgs) {
List<List<String>> datePairs = List.of(
List.of( "1943-03-09", "1972-07-11" ),
List.of( "1809-01-12", "1863-11-19" ),
List.of( "1809-02-12", "1863-11-19" ));
for ( List<String> datePair : datePairs ) {
biorhythms(datePair);
}
}
private static void biorhythms(List<String> aDatePair) {
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
LocalDate birthDate = LocalDate.parse(aDatePair.get(0), formatter);
LocalDate targetDate = LocalDate.parse(aDatePair.get(1), formatter);
final int daysBetween = (int) ChronoUnit.DAYS.between(birthDate, targetDate);
System.out.println("Birth date " + birthDate + ", Target date " + targetDate);
System.out.println("Days between: " + daysBetween);
for ( Cycle cycle : Cycle.values() ) {
final int cycleLength = cycle.length();
final int positionInCycle = daysBetween % cycleLength;
final int quadrantIndex = 4 * positionInCycle / cycleLength;
final int percentage = (int) Math.round(100 * Math.sin(2 * Math.PI * positionInCycle / cycleLength));
String description;
if ( percentage > 95 ) {
description = "peak";
} else if ( percentage < -95 ) {
description = "valley";
} else if ( Math.abs(percentage) < 5 ) {
description = "critical transition";
} else {
final int daysToTransition = ( cycleLength * ( quadrantIndex + 1 ) / 4 ) - positionInCycle;
LocalDate transitionDate = targetDate.plusDays(daysToTransition);
List<String> descriptions = cycle.descriptions(quadrantIndex);
String trend = descriptions.get(0);
String nextTransition = descriptions.get(1);
description = percentage + "% (" + trend + ", next " + nextTransition + " " + transitionDate + ")";
}
System.out.println(cycle + " day " + positionInCycle + ": " + description);
}
System.out.println();
}
private enum Cycle {
PHYSICAL(23), EMOTIONAL(28), MENTAL(33);
public int length() {
return length;
}
public List<String> descriptions(int aNumber) {
return DESCRIPTIONS.get(aNumber);
}
private Cycle(int aLength) {
length = aLength;
}
private final int length;
private static final List<List<String>> DESCRIPTIONS = List.of(
List.of( "up and rising", "peak" ), List.of( "up but falling", "transition" ),
List.of( "down and falling", "valley" ), List.of( "down but rising", "transition" ));
}
 
}
</syntaxhighlight>
<pre>
Birth date 1943-03-09, Target date 1972-07-11
Days between: 10717
PHYSICAL day 22: -27% (down but rising, next transition 1972-07-12)
EMOTIONAL day 21: valley
MENTAL day 25: valley
 
Birth date 1809-01-12, Target date 1863-11-19
Days between: 20034
PHYSICAL day 1: 27% (up and rising, next peak 1863-11-23)
EMOTIONAL day 14: critical transition
MENTAL day 3: 54% (up and rising, next peak 1863-11-24)
 
Birth date 1809-02-12, Target date 1863-11-19
Days between: 20003
PHYSICAL day 16: -94% (down and falling, next valley 1863-11-20)
EMOTIONAL day 11: 62% (up but falling, next transition 1863-11-22)
MENTAL day 5: 81% (up and rising, next peak 1863-11-22)
</pre>
 
=={{header|Julia}}==
{{trans|Raku}}
<langsyntaxhighlight lang="julia">using Dates
 
const cycles = ["Physical" => 23, "Emotional" => 28,"Mental" => 33]
Line 582 ⟶ 1,569:
tellfortune(Date("1809-01-12"), Date("1863-11-19"))
tellfortune(Date("1809-02-12"), Date("1863-11-19"))
</langsyntaxhighlight>{{out}}
<pre>
Born 1943-03-09, target date 1972-07-11
Line 602 ⟶ 1,589:
Mental day 5: 81.5% (up and rising, next peak 1863-11-22)
</pre>
 
 
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang="Kotlin">
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import kotlin.math.roundToInt
import kotlin.math.sin
 
fun main() {
val datePairs = listOf(
listOf("1943-03-09", "1972-07-11"),
listOf("1809-01-12", "1863-11-19"),
listOf("1809-02-12", "1863-11-19")
)
 
for (datePair in datePairs) {
calculateBiorhythms(datePair)
}
}
 
fun calculateBiorhythms(datePair: List<String>) {
val formatter = DateTimeFormatter.ISO_LOCAL_DATE
val birthDate = LocalDate.parse(datePair[0], formatter)
val targetDate = LocalDate.parse(datePair[1], formatter)
val daysBetween = ChronoUnit.DAYS.between(birthDate, targetDate).toInt()
println("Birth date $birthDate, Target date $targetDate")
println("Days between: $daysBetween")
 
for (cycle in Cycle.values()) {
val cycleLength = cycle.getLength()
val positionInCycle = daysBetween % cycleLength
val quadrantIndex = 4 * positionInCycle / cycleLength
val percentage = (100 * sin(2 * Math.PI * positionInCycle / cycleLength)).roundToInt()
 
val description = when {
percentage > 95 -> "peak"
percentage < -95 -> "valley"
Math.abs(percentage) < 5 -> "critical transition"
else -> {
val daysToTransition = (cycleLength * (quadrantIndex + 1) / 4) - positionInCycle
val transitionDate = targetDate.plusDays(daysToTransition.toLong())
val (trend, nextTransition) = cycle.descriptions(quadrantIndex)
"$percentage% ($trend, next $nextTransition $transitionDate)"
}
}
 
println("${cycle.name} day $positionInCycle: $description")
}
println()
}
 
enum class Cycle(private val length: Int) {
PHYSICAL(23), EMOTIONAL(28), MENTAL(33);
 
fun getLength() = length
 
fun descriptions(index: Int): Pair<String, String> {
val descriptions = listOf(
listOf("up and rising", "peak"),
listOf("up but falling", "transition"),
listOf("down and falling", "valley"),
listOf("down but rising", "transition")
)
return descriptions[index][0] to descriptions[index][1]
}
}
</syntaxhighlight>
{{out}}
<pre>
Birth date 1943-03-09, Target date 1972-07-11
Days between: 10717
PHYSICAL day 22: -27% (down but rising, next transition 1972-07-12)
EMOTIONAL day 21: valley
MENTAL day 25: valley
 
Birth date 1809-01-12, Target date 1863-11-19
Days between: 20034
PHYSICAL day 1: 27% (up and rising, next peak 1863-11-23)
EMOTIONAL day 14: critical transition
MENTAL day 3: 54% (up and rising, next peak 1863-11-24)
 
Birth date 1809-02-12, Target date 1863-11-19
Days between: 20003
PHYSICAL day 16: -94% (down and falling, next valley 1863-11-20)
EMOTIONAL day 11: 62% (up but falling, next transition 1863-11-22)
MENTAL day 5: 81% (up and rising, next peak 1863-11-22)
 
 
</pre>
 
 
=={{header|Locomotive Basic}}==
 
<syntaxhighlight lang="locobasic">10 input "Birthday (y,m,d) ",y,m,d:gosub 3000
20 gosub 1000
30 bday = day
40 input "Today's date (y,m,d) ",y,m,d:gosub 3000
50 gosub 1000
60 diff = day - bday
70 print:print "Age in days:" tab(22) diff
80 t$ = "physical":l = 23:gosub 2000
90 t$ = "emotional":l = 28:gosub 2000
100 t$ = "intellectual":l = 33:gosub 2000
999 end
1000 ' Get the days to J2000
1010 ' FNday only works between 1901 to 2099 - see Meeus chapter 7
1020 day = 367 * y - 7 * (y + (m + 9) \ 12) \ 4 + 275 * m \ 9 + d - 730530
1030 return
2000 p = 100 * sin(2*pi*diff/l)
2010 print t$; " cycle: " tab(22)
2020 print using "+###"; int(p);
2030 print "%";
2040 if abs(p) < 15 then print " (critical)" else print
2050 return
3000 if y < 1901 or y > 2099 then print "Year must be between 1901 and 2099!":run
3010 return</syntaxhighlight>
{{out}}
<pre>Birthday (y,m,d) 1943,3,9
Today's date (y,m,d) 1972,7,11
 
Age in days: 10717
physical cycle: -27%
emotional cycle: -100%
intellectual cycle: -100%</pre>
=={{header|Lua}}==
{{trans|Phix}}
<syntaxhighlight lang="lua">cycles = {"Physical day ", "Emotional day", "Mental day "}
lengths = {23, 28, 33}
quadrants = {
{"up and rising", "peak"},
{"up but falling", "transition"},
{"down and falling", "valley"},
{"down but rising", "transition"},
}
function parse_date_string (birthDate)
local year, month, day = birthDate:match("(%d+)-(%d+)-(%d+)")
return {year=tonumber(year), month=tonumber(month), day=tonumber(day)}
end
function days_diffeternce (d1, d2)
if d1.year >= 1970 and d2.year >= 1970 then
return math.floor(os.difftime(os.time(d2), os.time(d1))/(60*60*24))
else
local t1 = math.max (1970-d1.year, 1970-d2.year)
t1 = math.ceil(t1/4)*4
d1.year = d1.year + t1
d2.year = d2.year + t1
return math.floor(os.difftime(os.time(d2), os.time(d1))/(60*60*24))
end
end
function biorhythms (birthDate, targetDate)
local bd = parse_date_string(birthDate)
local td = parse_date_string(targetDate)
local days = days_diffeternce (bd, td)
print('Born: '.. birthDate .. ', Target: ' .. targetDate)
print("Day: ", days)
for i=1, #lengths do
local len = lengths[i]
local posn = days%len
local quadrant = math.floor(posn/len*4)+1
local percent = math.floor(math.sin(2*math.pi*posn/len)*1000)/10
local cycle = cycles[i]
local desc = percent > 95 and "peak" or
percent < -95 and "valley" or
math.abs(percent) < 5 and "critical transition" or "other"
if desc == "other" then
local t = math.floor(quadrant/4*len)-posn
local qtrend, qnext = quadrants[quadrant][1], quadrants[quadrant][2]
desc = percent .. '% (' .. qtrend .. ', next transition in ' .. t ..' days)'
end
print(cycle, posn..'/'..len, ': '.. desc)
end
print(' ')
end
datePairs = {
{"1943-03-09", "1972-07-11"},
{"1809-01-12", "1863-11-19"},
{"1809-02-12", "1863-11-19"},
{"2021-02-25", "2022-04-18"},
}
for i=1, #datePairs do
biorhythms(datePairs[i][1], datePairs[i][2])
end</syntaxhighlight>
 
{{out}}
<pre>Born: 1943-03-09, Target: 1972-07-11
Day: 10716
Physical day 21/23 : -52.0% (down but rising, next transition in 2 days)
Emotional day 20/28 : valley
Mental day 24/33 : valley
Born: 1809-01-12, Target: 1863-11-19
Day: 20034
Physical day 1/23 : 26.9% (up and rising, next transition in 4 days)
Emotional day 14/28 : critical transition
Mental day 3/33 : 54.0% (up and rising, next transition in 5 days)
Born: 1809-02-12, Target: 1863-11-19
Day: 20003
Physical day 16/23 : -94.3% (down and falling, next transition in 1 days)
Emotional day 11/28 : 62.3% (up but falling, next transition in 3 days)
Mental day 5/33 : 81.4% (up and rising, next transition in 3 days)
Born: 2021-02-25, Target: 2022-04-18
Day: 416
Physical day 2/23 : 51.9% (up and rising, next transition in 3 days)
Emotional day 24/28 : -78.2% (down but rising, next transition in 4 days)
Mental day 20/33 : -61.9% (down and falling, next transition in 4 days)</pre>
 
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
Module Biorhythms {
form 80
enum bio {Physical=23, Emotional=28,Mental=33}
quadrants=(("up and rising", "peak"), ("up but falling", "transition"), ("down and falling", "valley"), ("down but rising", "transition"))
date birth="1943-03-09"
date bioDay="1972-07-11", transition
for k=1 to 1
long Days=bioDay-birth
Print "Day "+Days+":"
 
string frm="{0:-20} : {1}", pword, dfmt="YYYY-MM-DD"
long position, percentage, length, targetday
k=each(bio)
while k
length=eval(k)
position=days mod length
quadrant=int(4*position/length)
targetday=bioDay // get the long value of day from date type
percentage=100*sin(360*position/length)
transition=bioDay+floor((quadrant+1)/4*23)-position
select case percentage
case >95
pword="peak"
case <-95
pword="valley"
case -5 to 5
pword="critical "
case else
{
pword=percentage+"% ("+quadrants#val(quadrant)#val$(0)+", next "
pword+=quadrants#val(quadrant)#val$(1)+" "+str$(transition,dfmt)+")"
}
end select
print format$(frm, eval$(k)+" day "+(days mod length), pword)
End while
bioDay++
next k
}
Biorhythms
</syntaxhighlight>
{{out}}
<pre>Day 10717:
Physical day 22: -27% (down but rising, next transition 1972-07-12)
Emotional day 21: valley
Mental day 25: valley
</pre>
 
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">targetdate = "1972-07-11";
birthdate = "1943-03-09";
targetdate //= DateObject;
Line 645 ⟶ 1,900:
,
{i, 3}
]</langsyntaxhighlight>
{{out}}
<pre>Day 10717:
Line 651 ⟶ 1,906:
Emotional day 21: valley
Mental day 25: valley</pre>
 
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import math
import strformat
import times
Line 715 ⟶ 1,969:
biorythms("1943-03-09", "1972-07-11")
biorythms("1809-01-12", "1863-11-19")
biorythms("1809-02-12", "1863-11-19")</langsyntaxhighlight>
 
{{out}}
Line 735 ⟶ 1,989:
Emotional day 11: 62.3% (up but falling, next transition 1863-11-22)
Mental day 5: 81.5% (up and rising, next peak 1863-11-22)</pre>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use DateTime;
Line 772 ⟶ 2,025:
}
printf "%-13s %2d: %s", "$label day\n", $position, $description;
}</langsyntaxhighlight>
{{out}}
<pre>Day 20003:
Line 778 ⟶ 2,031:
Mental day 5: 81.4% (up and rising, next peak 1863-11-22)
Physical day 16: -94.2% (down and falling, next valley 1863-11-20)</pre>
 
=={{header|Phix}}==
{{trans|Wren}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>include timedate.e
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
constant cycles = {"Physical day ", "Emotional day", "Mental day "},
lengths = {23, 28, 33},
<span style="color: #008080;">constant</span> <span style="color: #000000;">cycles</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Physical day "</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Emotional day"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Mental day "</span><span style="color: #0000FF;">},</span>
quadrants = {{"up and rising", "peak"},
<span style="color: #000000;">lengths</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">23</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">28</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">33</span><span style="color: #0000FF;">},</span>
{"up but falling", "transition"},
<span style="color: #000000;">quadrants</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #008000;">"up and rising"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"peak"</span><span style="color: #0000FF;">},</span>
{"down and falling", "valley"},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"up but falling"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"transition"</span><span style="color: #0000FF;">},</span>
{"down but rising", "transition"}}
<span style="color: #0000FF;">{</span><span style="color: #008000;">"down and falling"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"valley"</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">"down but rising"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"transition"</span><span style="color: #0000FF;">}}</span>
procedure biorhythms(string birthDate, targetDate)
timedate bd = parse_date_string(birthDate,{"YYYY-MM-DD"}),
<span style="color: #008080;">procedure</span> <span style="color: #000000;">biorhythms</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">birthDate</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">targetDate</span><span style="color: #0000FF;">)</span>
td = parse_date_string(targetDate,{"YYYY-MM-DD"})
<span style="color: #004080;">timedate</span> <span style="color: #000000;">bd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">birthDate</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">}),</span>
integer days = floor(timedate_diff(bd, td, DT_DAY)/(60*60*24))
<span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">targetDate</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">})</span>
printf(1,"Born %s, Target %s\n",{birthDate,targetDate})
<span style="color: #004080;">integer</span> <span style="color: #000000;">days</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">timedate_diff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bd</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">td</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">)/(</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">24</span><span style="color: #0000FF;">))</span>
printf(1,"Day %d\n",days)
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Born %s, Target %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">birthDate</span><span style="color: #0000FF;">,</span><span style="color: #000000;">targetDate</span><span style="color: #0000FF;">})</span>
for i=1 to 3 do
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Day %d\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">days</span><span style="color: #0000FF;">)</span>
integer len = lengths[i],
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">3</span> <span style="color: #008080;">do</span>
posn = remainder(days,len),
<span style="color: #004080;">integer</span> <span style="color: #000000;">len</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">lengths</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
quadrant = floor(posn/len*4)+1
<span style="color: #000000;">posn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">,</span><span style="color: #000000;">len</span><span style="color: #0000FF;">),</span>
atom percent = floor(sin(2*PI*posn/len)*1000)/10
<span style="color: #000000;">quadrant</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">posn</span><span style="color: #0000FF;">/</span><span style="color: #000000;">len</span><span style="color: #0000FF;">*</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span>
string cycle = cycles[i],
<span style="color: #004080;">atom</span> <span style="color: #000000;">percent</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">2</span><span style="color: #0000FF;">*</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">*</span><span style="color: #000000;">posn</span><span style="color: #0000FF;">/</span><span style="color: #000000;">len</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">10</span>
desc = iff(percent>95 ? " peak" :
<span style="color: #004080;">string</span> <span style="color: #000000;">cycle</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cycles</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
iff(percent<-95 ? " valley" :
<span style="color: #000000;">desc</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">percent</span><span style="color: #0000FF;">></span><span style="color: #000000;">95</span> <span style="color: #0000FF;">?</span> <span style="color: #008000;">" peak"</span> <span style="color: #0000FF;">:</span>
iff(abs(percent)<5 ? " critical transition" : "other")))
<span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">percent</span><span style="color: #0000FF;"><-</span><span style="color: #000000;">95</span> <span style="color: #0000FF;">?</span> <span style="color: #008000;">" valley"</span> <span style="color: #0000FF;">:</span>
if desc == "other" then
<span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">abs</span><span style="color: #0000FF;">(</span><span style="color: #000000;">percent</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">5</span> <span style="color: #0000FF;">?</span> <span style="color: #008000;">" critical transition"</span> <span style="color: #0000FF;">:</span> <span style="color: #008000;">"other"</span><span style="color: #0000FF;">)))</span>
timedate t = adjust_timedate(td,timedelta(days:=floor(quadrant/4*len)-posn))
<span style="color: #008080;">if</span> <span style="color: #000000;">desc</span> <span style="color: #0000FF;">==</span> <span style="color: #008000;">"other"</span> <span style="color: #008080;">then</span>
string transition = format_timedate(t,"YYYY-MM-DD"),
<span style="color: #004080;">timedate</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">adjust_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">td</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">quadrant</span><span style="color: #0000FF;">/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">*</span><span style="color: #000000;">len</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">posn</span><span style="color: #0000FF;">))</span>
{trend,next} = quadrants[quadrant]
<span style="color: #004080;">string</span> <span style="color: #000000;">transition</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">),</span>
desc = sprintf("%5.1f%% (%s, next %s %s)", {percent, trend, next, transition})
<span style="color: #0000FF;">{</span><span style="color: #000000;">trend</span><span style="color: #0000FF;">,</span><span style="color: #000000;">next</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">quadrants</span><span style="color: #0000FF;">[</span><span style="color: #000000;">quadrant</span><span style="color: #0000FF;">]</span>
end if
<span style="color: #000000;">desc</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%5.1f%% (%s, next %s %s)"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">percent</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">trend</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">next</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">transition</span><span style="color: #0000FF;">})</span>
printf(1,"%s %2d : %s\n", {cycle, posn, desc})
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end for
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s %2d : %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">cycle</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">posn</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">desc</span><span style="color: #0000FF;">})</span>
printf(1,"\n")
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end procedure
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
constant datePairs = {
{"1943-03-09", "1972-07-11"},
<span style="color: #008080;">constant</span> <span style="color: #000000;">datePairs</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span>
{"1809-01-12", "1863-11-19"},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"1943-03-09"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1972-07-11"</span><span style="color: #0000FF;">},</span>
{"1809-02-12", "1863-11-19"} // correct DOB for Abraham Lincoln
<span style="color: #0000FF;">{</span><span style="color: #008000;">"1809-01-12"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1863-11-19"</span><span style="color: #0000FF;">},</span>
}
<span style="color: #0000FF;">{</span><span style="color: #008000;">"1809-02-12"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1863-11-19"</span><span style="color: #0000FF;">}</span> <span style="color: #000080;font-style:italic;">// correct DOB for Abraham Lincoln</span>
for i=1 to length(datePairs) do biorhythms(datePairs[i][1], datePairs[i][2]) end for</lang>
<span style="color: #0000FF;">}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">datePairs</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">biorhythms</span><span style="color: #0000FF;">(</span><span style="color: #000000;">datePairs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">datePairs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 842 ⟶ 2,097:
Mental day 5 : 81.4% (up and rising, next peak 1863-11-22)
</pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">
"""
 
Line 909 ⟶ 2,163:
biorhythms("1943-03-09","1972-07-11")
</syntaxhighlight>
</lang>
 
{{out}}
Line 919 ⟶ 2,173:
Mental day 25: valley
</pre>
 
=={{header|R}}==
Also creates a plot showing past and future 30-day cycles
 
<langsyntaxhighlight Rlang="r">bioR <- function(bDay, targetDay) {
bDay <- as.Date(bDay)
targetDay <- as.Date(targetDay)
Line 965 ⟶ 2,218:
}
 
bioR('1943-03-09', '1972-07-11')</langsyntaxhighlight>
 
{{out}}
Line 976 ⟶ 2,229:
Mental = 25: Down and rising
</pre>
 
=={{header|Raku}}==
<langsyntaxhighlight lang="raku" line>#!/usr/bin/env raku
unit sub MAIN($birthday=%*ENV<BIRTHDAY>, $date = Date.today()) {
 
Line 1,014 ⟶ 2,266:
say "$label day $position: $description";
}
}</langsyntaxhighlight>
 
{{Out}}
Line 1,024 ⟶ 2,276:
Mental day 3: 54% (up and rising, next peak 1863-11-24)
</pre>
=={{header|Red}}==
{{trans|Raku}}
 
<syntaxhighlight lang="Red">
=={{header|REXX}}==
Red [
The &nbsp; '''daysbet2''' &nbsp; (REXX program) is used &nbsp; (invoked on line '''3''' of this program) &nbsp; to calculate the number of days between two dates,
Title: "Biorythms"
<br>where the dates can be in several formats:
Source: https://rosettacode.org/wiki/Biorhythms#Red
, (a comma) indicates today's date
Purpose: "Calculates biorythmic values for given birthday and target 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
 
biorythms: function [
It is usual to use the birth date of a person.
"Calculates biorythmic values for given birthday and target date"
<lang>/*REXX pgm shows the states of a person's biorhythms (physical, emotional, intellectual)*/
bday [date!]
parse arg birthdate targetDate . /*obtain one or two dates from the C.L.*/
target [date!]
days= daysbet2(birthdate targetDate) /*invoke the 2nd version of a REXX pgm.*/
][
if days==0 then do; say; say 'The two dates specified are exacty the same.'; exit 1
cycles: [
end
"Physical day " 23
cycles= 'physical emotional intellectual' /*the names of each biorhythm cycle*/
"Emotional day " 28
cycle = 'negative neutral positive' /* " states of " " " */
"Mental day " 33
@.1= 23; @.2= 28; @.3= 33 /* " # of days in " " " */
]
pid2= pi() * 2 * days /*calculate pi * t * number─of─days. */
 
quadrants: [
do j=1 for 3
["(up and rising" "peak"]
state= 2 + sign( sin( pid2 / @.j) ) /*obtain state for each biorhythm cycle*/
["(up but falling" "transition"]
say 'biorhythm for the' right(word(cycles,j),12) "cycle is" word(cycle, state)
["(down and falling" "valley"]
end /*j*/ /* [↑] get state for each biorhythm. */
["(down but rising" "transition"]
exit 0 /*stick a fork in it, we're all done. */
]
/*──────────────────────────────────────────────────────────────────────────────────────*/
pi: pi= 3.1415926535897932384626433832795028841971693993751058209749445923078; return pi
r2r: return arg(1) // (pi() * 2) /*normalize radians ──► a unit circle. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
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</lang>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 6/9/1946 </tt>}}
 
days: target - bday
Note: &nbsp; today's date is being used, &nbsp; today is the 6<sup>th</sup> of September, 2020.
 
print [
#"^(line)"
"Birthday :" bday #"^(line)"
"Target date:" target #"^(line)"
"Days :" days "days"
]
 
foreach [cycle len] cycles [
posn: days % len
quadrant: to-integer ((posn / len * 4) + 1)
ampl: to-percent round/to sin (days / len * 2 * pi) 0.01
trend: quadrants/(quadrant)
case [
ampl > 0.95 [desc: " Peak"]
ampl < -0.95 [desc: " Valley"]
(absolute ampl) <= 0.05 [desc: " Critical transition"]
true [
t: to-integer (quadrant / 4 * len) - posn
desc: reduce [pad/left ampl 4 trend/(1) ", next" trend/(2) "in" t "days)"]
]
]
print [cycle pad/left reduce [posn "of" len] 8 ":" desc]
]
]
 
biorythms 1943-03-09 1972-07-11 ; Bobby Fisher won the World Chess Championship
biorythms 1987-05-22 2023-01-29 ; Novak Đoković won the Australian Open for the 11th time
biorythms 1969-01-03 2013-09-13 ; Michael Schuhmacher's bad skiing accident
</syntaxhighlight>
 
{{out}}
<pre>
Birthday : 9-Mar-1943
biorhythm for the physical cycle is positive
Target date: 11-Jul-1972
biorhythm for the emotional cycle is neutral
Days : 10717 days
biorhythm for the intellectual cycle is negative
Physical day 22 of 23 : -27% (down but rising , next transition in 1 days)
Emotional day 21 of 28 : Valley
Mental day 25 of 33 : Valley
 
Birthday : 22-May-1987
Target date: 29-Jan-2023
Days : 13036 days
Physical day 18 of 23 : Valley
Emotional day 16 of 28 : -43% (down and falling , next valley in 5 days)
Mental day 1 of 33 : 19% (up and rising , next peak in 7 days)
 
Birthday : 3-Jan-1969
Target date: 13-Sep-2013
Days : 16324 days
Physical day 17 of 23 : Valley
Emotional day 0 of 28 : Critical transition
Mental day 22 of 33 : -87% (down and falling , next valley in 2 days)
</pre>
 
=={{header|REXX}}==
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 from CL */
If birthdate='?' Then Do
Say 'rexx bio birthdate (yyyymmdd) shows you today''s biorhythms'
Say 'or enter your birthday now'
Parse Pull birthdate
If birthdate='' Then Exit
End
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
/* compute the number of days between fromdate and todate */
Parse Arg fromdate,todate
fromday=date('B',fromdate,'S')
today=date('B',todate,'S')
Return today-fromday</syntaxhighlight>
{{out|output|text=&nbsp; when using the default dates}}
<pre>Birthdate: 19460906 (06.09.1946)
Today: 20200906 (06.09.2020)
Elapsed days: 27029
biorhythm for the physical cycle is positive
biorhythm for the emotional cycle is positive
biorhythm for the intellectual cycle is positive</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight Rubylang="ruby">require 'date'
CYCLES = {physical: 23, emotional: 28, mental: 33}
 
Line 1,086 ⟶ 2,455:
biorhythms("1943-03-09", "1972-07-11")
</syntaxhighlight>
</lang>
{{out}}
<pre>physical : cycle day 22, negative
emotional : cycle day 21, negative
mental : cycle day 25, negative
</pre>
 
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="Scala">
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import scala.collection.JavaConverters._
 
object Biorythms extends App {
 
val datePairs = List(
List("1943-03-09", "1972-07-11"),
List("1809-01-12", "1863-11-19"),
List("1809-02-12", "1863-11-19")
)
 
datePairs.foreach(biorhythms)
 
def biorhythms(aDatePair: List[String]): Unit = {
val formatter = DateTimeFormatter.ISO_LOCAL_DATE
val birthDate = LocalDate.parse(aDatePair.head, formatter)
val targetDate = LocalDate.parse(aDatePair(1), formatter)
val daysBetween = ChronoUnit.DAYS.between(birthDate, targetDate).toInt
println(s"Birth date $birthDate, Target date $targetDate")
println(s"Days between: $daysBetween")
 
for (cycle <- Cycle.values) {
val cycleLength = cycle.length
val positionInCycle = daysBetween % cycleLength
val quadrantIndex = 4 * positionInCycle / cycleLength
val percentage = Math.round(100 * Math.sin(2 * Math.PI * positionInCycle / cycleLength)).toInt
 
val description = if (percentage > 95) {
"peak"
} else if (percentage < -95) {
"valley"
} else if (Math.abs(percentage) < 5) {
"critical transition"
} else {
val daysToTransition = (cycleLength * (quadrantIndex + 1) / 4) - positionInCycle
val transitionDate = targetDate.plusDays(daysToTransition)
val descriptions = cycle.descriptions(quadrantIndex).asScala
val trend = descriptions.head
val nextTransition = descriptions(1)
s"$percentage% ($trend, next $nextTransition $transitionDate)"
}
 
println(s"${cycle} day $positionInCycle: $description")
}
println()
}
 
enum Cycle(val length: Int) {
case PHYSICAL extends Cycle(23)
case EMOTIONAL extends Cycle(28)
case MENTAL extends Cycle(33)
 
def descriptions(number: Int): java.util.List[String] = Cycle.DESCRIPTIONS.get(number)
}
 
object Cycle {
private val DESCRIPTIONS = java.util.List.of(
java.util.List.of("up and rising", "peak"),
java.util.List.of("up but falling", "transition"),
java.util.List.of("down and falling", "valley"),
java.util.List.of("down but rising", "transition")
)
}
 
}
</syntaxhighlight>
{{out}}
<pre>
Birth date 1943-03-09, Target date 1972-07-11
Days between: 10717
PHYSICAL day 22: -27% (down but rising, next transition 1972-07-12)
EMOTIONAL day 21: valley
MENTAL day 25: valley
 
Birth date 1809-01-12, Target date 1863-11-19
Days between: 20034
PHYSICAL day 1: 27% (up and rising, next peak 1863-11-23)
EMOTIONAL day 14: critical transition
MENTAL day 3: 54% (up and rising, next peak 1863-11-24)
 
Birth date 1809-02-12, Target date 1863-11-19
Days between: 20003
PHYSICAL day 16: -94% (down and falling, next valley 1863-11-20)
EMOTIONAL day 11: 62% (up but falling, next transition 1863-11-22)
MENTAL day 5: 81% (up and rising, next peak 1863-11-22)
 
 
</pre>
 
Line 1,096 ⟶ 2,559:
{{works with|Wish}}
A graphing version using Tcl+Tk:
<langsyntaxhighlight lang="tcl">#!/usr/bin/env wish
# Biorhythm calculator
set today [clock format [clock seconds] -format %Y-%m-%d ]
Line 1,164 ⟶ 2,627:
}
 
main {*}$argv</langsyntaxhighlight>
{{Out}}
Output of <langsyntaxhighlight lang="sh">wish br.wish 1809-02-12 1863-11-19</langsyntaxhighlight> - Lincoln's biorhythms at Gettysburg:
https://i.imgur.com/U2izZOM.png
 
=={{header|VBA}}==
{{trans|Wren}}
<langsyntaxhighlight lang="vb">Function Biorhythm(Birthdate As Date, Targetdate As Date) As String
 
'Jagged Array
Line 1,241 ⟶ 2,703:
Debug.Print ""
 
End Function</langsyntaxhighlight>
{{Out}}
<pre>
Line 1,261 ⟶ 2,723:
Emotional day 14 : critical transition
Mental day 3 : 54.1% (up and rising, next peak 24.11.1863)
</pre>
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">import time
import math
const cycles = ["Physical day ", "Emotional day", "Mental day "]
const lengths = [23, 28, 33]
const quadrants = [
["up and rising", "peak"],
["up but falling", "transition"],
["down and falling", "valley"],
["down but rising", "transition"],
]
// Parameters assumed to be in YYYY-MM-DD format.
fn biorhythms(birth_date string, target_date string) ? {
bd := time.parse_iso8601(birth_date)?
td := time.parse_iso8601(target_date)?
days := int((td-bd).hours() / 24)
println("Born $birth_date, Target $target_date")
println("Day $days")
for i in 0..3 {
length := lengths[i]
cycle := cycles[i]
position := days % length
quadrant := position * 4 / length
mut percent := math.sin(2 * math.pi * f64(position) / f64(length))
percent = math.floor(percent*1000) / 10
mut descript := ""
if percent > 95 {
descript = " peak"
} else if percent < -95 {
descript = " valley"
} else if math.abs(percent) < 5 {
descript = " critical transition"
} else {
days_to_add := (quadrant+1)*length/4 - position
transition := td.add(time.hour * 24 * time.Duration(days_to_add))
trend := quadrants[quadrant][0]
next := quadrants[quadrant][1]
trans_str := transition.custom_format('YYYY-MM-DD')
descript = "${percent:5.1f}% ($trend, next $next $trans_str)"
}
println("$cycle ${position:2} : $descript")
}
println('')
}
fn main() {
date_pairs := [
["1943-03-09", "1972-07-11"],
["1809-01-12", "1863-11-19"],
["1809-02-12", "1863-11-19"], // correct DOB for Abraham Lincoln
]
for date_pair in date_pairs {
biorhythms(date_pair[0], date_pair[1])?
}
}</syntaxhighlight>
 
{{out}}
<pre>
Born 1943-03-09, Target 1972-07-11
Day 10717
Physical day 22 : -27.0% (down but rising, next transition 1972-07-12)
Emotional day 21 : valley
Mental day 25 : valley
 
Born 1809-01-12, Target 1863-11-19
Day 20034
Physical day 1 : 26.9% (up and rising, next peak 1863-11-23)
Emotional day 14 : critical transition
Mental day 3 : 54.0% (up and rising, next peak 1863-11-24)
 
Born 1809-02-12, Target 1863-11-19
Day 20003
Physical day 16 : -94.3% (down and falling, next valley 1863-11-20)
Emotional day 11 : 62.3% (up but falling, next transition 1863-11-22)
Mental day 5 : 81.4% (up and rising, next peak 1863-11-22)
</pre>
 
Line 1,267 ⟶ 2,808:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./date" for Date
import "./fmt" for Fmt
 
var cycles = ["Physical day ", "Emotional day", "Mental day "]
Line 1,312 ⟶ 2,853:
["1809-02-12", "1863-11-19"] // correct DOB for Abraham Lincoln
]
for (datePair in datePairs) biorhythms.call(datePair[0], datePair[1])</langsyntaxhighlight>
 
{{out}}
1,983

edits