Biorhythms: Difference between revisions

1,397 bytes added ,  2 years ago
no edit summary
No edit summary
Line 602:
Mental day 5: 81.5% (up and rising, next peak 1863-11-22)
</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>targetdate = "1972-07-11";
birthdate = "1943-03-09";
targetdate //= DateObject;
birthdate //= DateObject;
 
cyclelabels = {"Physical", "Emotional", "Mental"};
cyclelengths = {23, 28, 33};
quadrants = {{"up and rising", "peak"}, {"up but falling",
"transition"}, {"down and falling", "valley"}, {"down but rising",
"transition"}};
 
d = QuantityMagnitude[DateDifference[birthdate, targetdate], "Days"];
Print["Day ", d, ":"];
Do[
label = cyclelabels[[i]];
length = cyclelengths[[i]];
position = Mod[d, length];
quadrant = Floor[4 (position + 1)/length];
percentage = Round[100*Sin[2*Pi*position/length]];
transitiondate =
DatePlus[targetdate, Floor[(quadrant + 1)/4*length] - position];
{trend, next} = quadrants[[quadrant]];
If[percentage > 95,
description = "peak"
,
If[percentage < -95,
description = "valley"
,
If[Abs[percentage] < 5,
description = "critical transition"
,
description =
ToString[percentage] <> "% (" <> trend <> ", next " <> next <>
" " <> DateString[transitiondate, "ISODate"] <> ")"
]
]
];
Print[label <> " day " <> ToString[position] <> ": " <>
description];
,
{i, 3}
]</lang>
{{out}}
<pre>Day 10717:
Physical day 22: -27% (down but rising, next transition 1972-07-17)
Emotional day 21: valley
Mental day 25: valley</pre>
 
=={{header|Nim}}==
1,111

edits