How to resolve the algorithm Biorhythms step by step in the J programming language
How to resolve the algorithm Biorhythms step by step in the J programming language
Table of Contents
Problem Statement
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 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. The three cycles and their lengths are as follows: The first half of each cycle is in "plus" territory, with a peak at the quarter-way point; the second half in "minus" territory, with a valley at the three-quarters mark. You can calculate a specific value between -1 and +1 for the kth day of an n-day cycle by computing sin( 2πk / n ). The days where a cycle crosses the axis in either direction are called "critical" days, although with a cycle value of 0 they're also said to be the most neutral, which seems contradictory. The task: write a subroutine, function, or program that will, given a birthdate and a target date, output the three biorhythmic values for the day. You may optionally include a text description of the position and the trend (e.g. "up and rising", "peak", "up but falling", "critical", "down and falling", "valley", "down but rising"), an indication of the date on which the next notable event (peak, valley, or crossing) falls, or even a graph of the cycles around the target date. Demonstrate the functionality for dates of your choice. Example run of my Raku implementation: Double valley! This was apparently not a good day for Mr. Fischer to begin a chess tournament...
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Biorhythms step by step in the J programming language
Source code in the j programming language
use=: 'Use: ', (;:inv 2 {. ARGV) , ' YYYY-MM-DD YYYY-MM-DD'
3 :0 ::echo use
TAU=: 2p1 NB. tauday.com
require'plot ~addons/types/datetime/datetime.ijs'
span=: (i.7) + daysDiff&(1 0 0 0 1 0 1 0 ".;.1 -.&'-')~
Length=: 23 5 p. i. 3
arg=: Length *inv TAU * Length |/ span
brtable=: 1 o. arg
biorhythm=: 'title biorythms for the week ahead; key Physical Emotional Mental' plot (i.7) (j."1) brtable~
biorhythm/ 2 3 {::"0 1 ARGV
echo 'find new graph (plot.pdf) in directory ' , jpath '~temp/'
brs=. brtable/ 2 3 {::"0 1 ARGV
echo (a:,'values';'interpretation') ,: (4 10 $ 'days aheadPhysical Emotional Mental ') ; (1 3 # 6 6j1)&(":"0 1) L:0 (; |) brs ,~ i. 7
)
exit 0
You may also check:How to resolve the algorithm Four bit adder step by step in the Sather programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the Oforth programming language
You may also check:How to resolve the algorithm Jewels and stones step by step in the D programming language
You may also check:How to resolve the algorithm Pi step by step in the EDSAC order code programming language
You may also check:How to resolve the algorithm Execute a Markov algorithm step by step in the PHP programming language