Rebol3 Code Examplex
Biorhythms
Calculate and display personal biorhythm cycles.
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
Output:
Birthday...... 9-Mar-1943
Target date... 11-Jul-1972
Days.......... 10717 days
Physical day 22 of 23 : -27% (down but rising, nexttransition 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, nextvalley in 5 days)
Mental day 1 of 33 : 19% (up and rising, nextpeak 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, nextvalley in 2 days)