Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,65 @@
with Ada.Calendar;
with Ada.Calendar.Arithmetic;
with Ada.Calendar.Formatting;
with Ada.Command_Line;
with Ada.Numerics;
with Ada.Numerics.Elementary_Functions;
with Ada.Text_IO;
use Ada.Calendar;
use Ada.Calendar.Arithmetic;
use Ada.Calendar.Formatting;
use Ada.Command_Line;
use Ada.Numerics;
use Ada.Numerics.Elementary_Functions;
use Ada.Text_IO;
procedure Biorhythms is
Birth_Date : Time := Value (Argument (1) & " 00:00:00");
Target_Date : Time := Value (Argument (2) & " 00:00:00");
Days : Day_Count := Target_Date - Birth_Date;
-- There's not much point having types for these for such a short
-- problem, but in a big program this would be useful to prevent
-- accidentally assigning wrong values.
type Physical_Type is mod 23;
type Emotional_Type is mod 28;
type Mental_Type is mod 33;
type Biorhythm_Type is
record
Physical : Physical_Type;
Emotional : Emotional_Type;
Mental : Mental_Type;
end record;
function To_Biorhythm (D : Day_Count) return Biorhythm_Type is
(
Physical_Type (D mod Physical_Type'Modulus),
Emotional_Type (D mod Emotional_Type'Modulus),
Mental_Type (D mod Mental_Type'Modulus)
);
Biorhythm : Biorhythm_Type := To_Biorhythm (Days);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
use Float_IO;
function To_Percent (F : Float) return Float is
(100.0 * Sin (2.0 * Pi * F));
procedure Report_Biorhythm (B : Biorhythm_Type) is
PFrac : Float := Float (B.Physical) / Float (Physical_Type'Modulus);
EFrac : Float := Float (B.Emotional) / Float (Emotional_Type'Modulus);
MFrac : Float := Float (B.Mental) / Float (Mental_Type'Modulus);
Physical : Float := To_Percent (PFrac);
Emotional : Float := To_Percent (EFrac);
Mental : Float := To_Percent (MFrac);
begin
Put_Line ("Age in days: " & Days'Image);
Put ("Physical cycle: "); Put (Physical, 3, 1, 0); Put ("%"); New_Line;
Put ("Emotional cycle: "); Put (Emotional, 3, 1, 0); Put ("%"); New_Line;
Put ("Mental cycle: "); Put (Mental, 3, 1, 0); Put ("%"); New_Line;
end Report_Biorhythm;
begin
Report_Biorhythm (Biorhythm);
end Biorhythms;

View file

@ -0,0 +1,144 @@
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
.

View file

@ -0,0 +1,9 @@
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%

View file

@ -0,0 +1,48 @@
module BioRhythms
enum Cycle
Physical = 23
Emotional = 28
Mental = 33
end
Quadrants = [ {"up and raising", "peak"},
{"up but falling", "transition"},
{"down and falling", "valley"},
{"down but raising", "transition"} ]
def self.report (birthday, date = Time.utc)
# regularize to avoid fractional days difference
birthday, date = birthday.to_utc, date.to_utc
birthday -= birthday.time_of_day
date -= date.time_of_day
days = (date - birthday).days
puts "Born #{birthday.to_s("%F")}, Target #{date.to_s("%F")}"
puts "Day #{days}:"
Cycle.each do |kind, length|
position = days % length
quadrant = (position / length * 4).to_i
percentage = (Math.sin(position / length * 2 * Math::PI)*1000).to_i / 10
description = if percentage > 95
"peak"
elsif percentage < -95
"valley"
elsif percentage.abs < 5
"critical transition"
else
transition = date + ((quadrant + 1)/4 * length).to_i.days - position.days
trend, the_next = Quadrants[quadrant]
"#{percentage}% (#{trend}, next #{the_next} #{transition.to_s("%F")})"
end
puts "%-13s %2d: %s" % {kind.to_s + " day", position, description}
end
end
end
[{"1943-03-09", "1972-07-11"},
{"1809-01-12", "1863-11-19"},
{"1809-02-12", "1863-11-19"}].each do |bd, target|
BioRhythms.report Time.parse_utc(bd, "%F"), Time.parse_utc(target, "%F")
puts
end

View file

@ -28,10 +28,10 @@ proc cycle now cyc t$ col .
gtext 4 cyc * 1.2 - 20 t$
glinewidth 0.5
gpenup
for d = now - 20 to now + 20
for d = now - 20 step 0.2 to now + 20
y = 50 + 20 * sin (360 * d / cyc)
glineto x y
x += 2.5
x += 0.5
.
.
days = init birth$ date$

View file

@ -0,0 +1,15 @@
(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))))

View file

@ -1,44 +1,42 @@
(phixonline)-->
<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>
with javascript_semantics
include timedate.e
<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>
<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>
<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>
<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>
<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>
constant 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"}}
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<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>
procedure biorhythms(string birthDate, targetDate)
timedate bd = parse_date_string(birthDate,{"YYYY-MM-DD"}),
td = parse_date_string(targetDate,{"YYYY-MM-DD"})
integer days = floor(timedate_diff(bd, td, DT_DAY)/(60*60*24))
printf(1,"Born %s, Target %s\n",{birthDate,targetDate})
printf(1,"Day %d\n",days)
for i=1 to 3 do
integer len = lengths[i],
posn = remainder(days,len),
quadrant = floor(posn/len*4)+1
atom percent = floor(sin(2*PI*posn/len)*1000)/10
string cycle = cycles[i],
desc = iff(percent>95 ? " peak" :
iff(percent<-95 ? " valley" :
iff(abs(percent)<5 ? " critical transition" : "other")))
if desc == "other" then
timedate t = adjust_timedate(td,timedelta(days:=floor(quadrant/4*len)-posn))
string transition = format_timedate(t,"YYYY-MM-DD"),
{trend,next} = quadrants[quadrant]
desc = sprintf("%5.1f%% (%s, next %s %s)", {percent, trend, next, transition})
end if
printf(1,"%s %2d : %s\n", {cycle, posn, desc})
end for
printf(1,"\n")
end procedure
<span style="color: #008080;">constant</span> <span style="color: #000000;">datePairs</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span>
<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>
<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>
<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>
<!--
constant datePairs = {
{"1943-03-09", "1972-07-11"},
{"1809-01-12", "1863-11-19"},
{"1809-02-12", "1863-11-19"} // correct DOB for Abraham Lincoln
}
for i=1 to length(datePairs) do biorhythms(datePairs[i][1], datePairs[i][2]) end for

View file

@ -0,0 +1,55 @@
local fmt = require "fmt"
local cycles = {"Physical day ", "Emotional day", "Mental day "}
local lengths = {23, 28, 33}
local quadrants = {
{"up and rising", "peak"},
{"up but falling", "transition"},
{"down and falling", "valley"},
{"down but rising", "transition"}
}
local function date_parse(date)
local year = tonumber(date:sub(1, 4))
local month = tonumber(date:sub(6, 7))
local day = tonumber(date:sub(9, 10))
return year, month, day
end
local function biorhythms(birth_date, target_date)
local y, m, d = date_parse(birth_date)
local bd = os.time({year = y, month = m, day = d})
y, m, d = date_parse(target_date)
local td = os.time({year = y, month = m, day = d})
local days = math.round((td - bd) / 86400)
print($"Born {birth_date}, Target {target_date}")
print($"Day {days}")
for i = 1, 3 do
local length = lengths[i]
local cycle = cycles[i]
local position = days % length
local quadrant = math.floor(position / length * 4)
local percent = math.floor(math.sin(2 * math.pi * position / length) * 1000) / 10
local descript = (percent > 95) ? " peak" :
(percent < -95) ? " valley" :
(math.abs(percent) < 5) ? " critical transition" : "other"
if descript == "other" then
local add_days = math.floor((quadrant + 1) / 4 * length) - position
local transition = os.time({year = y, month = m, day = d + add_days})
local trans_date = os.date("%F", transition)
local tn = quadrants[quadrant + 1]
local trend = tn[1]
local nxt = tn[2]
descript = string.format("%5.1f%% (%s, next %s %s)", percent, trend, nxt, trans_date)
end
fmt.print("%s %2d : %s", cycle, position, descript)
end
print()
end
local 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_pairs as date_pair do biorhythms(date_pair[1], date_pair[2]) end

View file

@ -0,0 +1,58 @@
local fmt = require "fmt"
local cycles = {"Physical day ", "Emotional day", "Mental day "}
local lengths = {23, 28, 33}
local quadrants = {
{"up and rising", "peak"},
{"up but falling", "transition"},
{"down and falling", "valley"},
{"down but rising", "transition"}
}
local function date_parse(date)
local year = tonumber(date:sub(1, 4))
local month = tonumber(date:sub(6, 7))
local day = tonumber(date:sub(9, 10))
return year, month, day
end
local function biorhythms(birth_date, target_date)
local y, m, d = date_parse(birth_date)
local bday = os.time({year = y + 400, month = m, day = d})
y, m, d = date_parse(target_date)
local tday = os.time({year = y + 400, month = m, day = d})
local days = math.round((tday - bday) / 86400)
print($"Born {birth_date}, Target {target_date}")
print($"Day {days}")
for i = 1, 3 do
local length = lengths[i]
local cycle = cycles[i]
local position = days % length
local quadrant = math.floor(position / length * 4)
local percent = math.floor(math.sin(2 * math.pi * position / length) * 1000) / 10
local descript = (percent > 95) ? " peak" :
(percent < -95) ? " valley" :
(math.abs(percent) < 5) ? " critical transition" : "other"
if descript == "other" then
local add_days = math.floor((quadrant + 1) / 4 * length) - position
local transition = os.time({year = y + 400, month = m, day = d + add_days})
local trans_date = os.date("%F", transition)
local ty, tm, td = date_parse(trans_date)
ty -= 400
trans_date = string.format("%04d-%02d-%02d", ty, tm, td)
local tn = quadrants[quadrant + 1]
local trend = tn[1]
local nxt = tn[2]
descript = string.format("%5.1f%% (%s, next %s %s)", percent, trend, nxt, trans_date)
end
fmt.print("%s %2d : %s", cycle, position, descript)
end
print()
end
local 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_pairs as date_pair do biorhythms(date_pair[1], date_pair[2]) end

View file

@ -0,0 +1,53 @@
Rebol [
title: "Rosetta code: Biorhythms"
file: %Biorhythms.r3
url: https://rosettacode.org/wiki/Biorhythms
note: "Based on Red language implementation!"
needs: 3.10.0 ;; or something like that
]
biorythms: function/with [
"Calculates biorythmic values for given birthday and target date"
bday [date!]
target [date!]
][
days: target - bday
print [
"^/Birthday......" bday
"^/Target date..." target
"^/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
desc: case [
ampl > 0.95 [" Peak"]
ampl < -0.95 [" Valley"]
0.05 >= absolute ampl [" Critical transition"]
true [
t: to integer! (quadrant / 4 * len) - posn
ajoin [pad ampl -4 SP trend/1 ", next" trend/2 " in " t " days)"]
]
]
print [cycle pad reduce [posn "of" len] -8 ":" desc]
]
][
cycles: [
"Physical day " 23
"Emotional day " 28
"Mental day " 33
]
quadrants: [
["(up and rising" "peak" ]
["(up but falling" "transition"]
["(down and falling" "valley" ]
["(down but rising" "transition"]
]
]
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