RosettaCodeData/Task/Biorhythms/Mathematica/biorhythms.math

43 lines
1.1 KiB
Plaintext

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}
]