Biorhythms: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 27:
 
Example run of my Raku implementation:
<langsyntaxhighlight lang=sh>raku br.raku 1943-03-09 1972-07-11</langsyntaxhighlight>
{{Out}}
Line 41:
{{trans|Python}}
 
<langsyntaxhighlight lang=11l>F biorhythms(birthdate_str, targetdate_str)
Print out biorhythm data for targetdate assuming you were
Line 84:
print(label‘ day ’position‘: ’description)
 
biorhythms(‘2043-03-09’, ‘2072-07-11’)</langsyntaxhighlight>
 
{{out}}
Line 97:
=={{header|C}}==
{{trans|Locomotive Basic}}
<langsyntaxhighlight lang=c>#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Line 127:
cycle(diff, 28, "Emotional");
cycle(diff, 33, "Intellectual");
}</langsyntaxhighlight>
Test:
<langsyntaxhighlight lang=bash>gcc -o cbio cbio.c -lm
./cbio 1972 7 11 1943 3 9
Age: 10717 days
Physical cycle: -27%
Emotional cycle: -100%
Intellectual cycle: -100%</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{trans|Locomotive Basic}}
<langsyntaxhighlight lang=cobol>
 
identification division.
Line 285:
.
 
</syntaxhighlight>
</lang>
Test:
<langsyntaxhighlight lang=bash>
Compile and Test
C:\GnuCOBOL>
Line 296:
Physical 01:+027.0%
Emotional 14:+000.0% critical
Mental 03:+054.1%</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
{{trans|Locomotive Basic}}
<langsyntaxhighlight lang=lisp>;;;; Common Lisp biorhythms
 
;;; Get the days to J2000
Line 330:
(print-cycle diff 23 "physical")
(print-cycle diff 28 "emotional")
(print-cycle diff 33 "intellectual")))</langsyntaxhighlight>
{{output}}
<pre>* (print-bio 1972 7 11 1943 3 9)
Line 342:
{{libheader| System.Math}}
{{Trans|Go}}
<langsyntaxhighlight lang=Delphi>
program Biorhythms;
 
Line 446:
CalcBiorhythms(datePairs[i, 0], datePairs[i, 1]);
readln;
end.</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
For Emacs, it makes sense to implement this as an interactive command which is personalized to the user's birthdate and computes the biorhythm for today. So if you put this code into your .emacs file (note that the birthdate has to be in MDY order in Emacs!):
<langsyntaxhighlight lang=lisp>(require 'calendar)
 
(setq biorhythm-birthdate '(3 16 1953))
Line 464:
(* 2 pi diff (/ 1.0 x)))))) rhyt)))
(message "age: %i physical: %i%% emotional: %i%% intellectual: %i%%"
diff (car perc) (cadr perc) (caddr perc))))</langsyntaxhighlight>
Then typing "M-x biorhythm" will produce this output in the Emacs echo area on 2022-04-21:
<pre>
Line 471:
 
=={{header|Factor}}==
<langsyntaxhighlight lang=factor>USING: calendar calendar.parser formatting io kernel math
math.constants math.functions ;
 
Line 492:
[ 33 "Mental" .day ] tri ;
 
"1809-02-12" "1863-11-19" .biorhythm</langsyntaxhighlight>
{{out}}
<pre>
Line 504:
=={{header|FOCAL}}==
{{trans|Locomotive Basic}}
<langsyntaxhighlight lang=FOCAL>1.01 T "Enter birthdate (y,m,d)",!
1.02 ASK Y,M,D
1.03 D 2; S BZ=Z
Line 530:
4.1 T " CRITICAL",!
 
5.1 T !</langsyntaxhighlight>
{{output}}
<pre>*G
Line 547:
 
 
<langsyntaxhighlight lang=Fortran>C ------------------------------------------------------------------
PROGRAM BIORHYTHM
C ------------------------------------------------------------------
Line 718:
RETURN
END</langsyntaxhighlight>
 
{{in}}
Line 781:
=={{header|FreeBASIC}}==
{{trans|VBA}}
<langsyntaxhighlight lang=freebasic>#define floor(x) ((x*2.0-0.5) Shr 1)
#define pi (4 * Atn(1))
 
Line 867:
Biorhythm("1809-02-12", "1863-11-19") 'correct DOB for Abraham Lincoln
Biorhythm("1809-01-12", "1863-11-19")
</syntaxhighlight>
</lang>
 
 
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang=go>package main
 
import (
Line 943:
biorhythms(datePair[0], datePair[1])
}
}</langsyntaxhighlight>
 
{{out}}
Line 968:
=={{header|J}}==
Let's presume the content of file <tt>br.ijs</tt> :
<syntaxhighlight lang=J>
<lang J>
use=: 'Use: ', (;:inv 2 {. ARGV) , ' YYYY-MM-DD YYYY-MM-DD'
 
Line 989:
 
exit 0
</syntaxhighlight>
</lang>
Then bash commands could be
<pre>
Line 1,008:
=={{header|Julia}}==
{{trans|Raku}}
<langsyntaxhighlight lang=julia>using Dates
 
const cycles = ["Physical" => 23, "Emotional" => 28,"Mental" => 33]
Line 1,036:
tellfortune(Date("1809-01-12"), Date("1863-11-19"))
tellfortune(Date("1809-02-12"), Date("1863-11-19"))
</langsyntaxhighlight>{{out}}
<pre>
Born 1943-03-09, target date 1972-07-11
Line 1,059:
=={{header|Locomotive Basic}}==
 
<langsyntaxhighlight lang=locobasic>10 input "Birthday (y,m,d) ",y,m,d:gosub 3000
20 gosub 1000
30 bday = day
Line 1,081:
2050 return
3000 if y < 1901 or y > 2099 then print "Year must be between 1901 and 2099!":run
3010 return</langsyntaxhighlight>
{{out}}
<pre>Birthday (y,m,d) 1943,3,9
Line 1,093:
=={{header|Lua}}==
{{trans|Phix}}
<langsyntaxhighlight lang=Lua>cycles = {"Physical day ", "Emotional day", "Mental day "}
lengths = {23, 28, 33}
quadrants = {
Line 1,154:
for i=1, #datePairs do
biorhythms(datePairs[i][1], datePairs[i][2])
end</langsyntaxhighlight>
 
{{out}}
Line 1,182:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>targetdate = "1972-07-11";
birthdate = "1943-03-09";
targetdate //= DateObject;
Line 1,223:
,
{i, 3}
]</langsyntaxhighlight>
{{out}}
<pre>Day 10717:
Line 1,232:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight lang=Nim>import math
import strformat
import times
Line 1,293:
biorythms("1943-03-09", "1972-07-11")
biorythms("1809-01-12", "1863-11-19")
biorythms("1809-02-12", "1863-11-19")</langsyntaxhighlight>
 
{{out}}
Line 1,316:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang=perl>use strict;
use warnings;
use DateTime;
Line 1,350:
}
printf "%-13s %2d: %s", "$label day\n", $position, $description;
}</langsyntaxhighlight>
{{out}}
<pre>Day 20003:
Line 1,359:
=={{header|Phix}}==
{{trans|Wren}}
<!--<langsyntaxhighlight lang=Phix>(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>
Line 1,402:
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,427:
 
=={{header|Python}}==
<langsyntaxhighlight lang=python>
"""
 
Line 1,492:
biorhythms("1943-03-09","1972-07-11")
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,506:
Also creates a plot showing past and future 30-day cycles
 
<langsyntaxhighlight lang=R>bioR <- function(bDay, targetDay) {
bDay <- as.Date(bDay)
targetDay <- as.Date(targetDay)
Line 1,548:
}
 
bioR('1943-03-09', '1972-07-11')</langsyntaxhighlight>
 
{{out}}
Line 1,561:
 
=={{header|Raku}}==
<syntaxhighlight lang=raku perl6line>#!/usr/bin/env raku
unit sub MAIN($birthday=%*ENV<BIRTHDAY>, $date = Date.today()) {
 
Line 1,597:
say "$label day $position: $description";
}
}</langsyntaxhighlight>
 
{{Out}}
Line 1,620:
 
It is usual to use the birth date of a person.
<syntaxhighlight lang=text>/*REXX pgm shows the states of a person's biorhythms (physical, emotional, intellectual)*/
parse arg birthdate targetDate . /*obtain one or two dates from the C.L.*/
days= daysbet2(birthdate targetDate) /*invoke the 2nd version of a REXX pgm.*/
Line 1,642:
if x=pi * .5 then return 1; if x==pi*1.5 then return -1
if abs(x)=pi | x=0 then return 0; q= x*x; z= x
do k=2 by 2 until p=z; p= z; _= -_ *q/(k*k+k); z= z+_; end; return z</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 6/9/1946 </tt>}}
 
Line 1,652:
</pre>
=={{header|Ruby}}==
<langsyntaxhighlight lang=Ruby>require 'date'
CYCLES = {physical: 23, emotional: 28, mental: 33}
 
Line 1,669:
biorhythms("1943-03-09", "1972-07-11")
</syntaxhighlight>
</lang>
{{out}}
<pre>physical : cycle day 22, negative
Line 1,679:
{{works with|Wish}}
A graphing version using Tcl+Tk:
<langsyntaxhighlight lang=tcl>#!/usr/bin/env wish
# Biorhythm calculator
set today [clock format [clock seconds] -format %Y-%m-%d ]
Line 1,747:
}
 
main {*}$argv</langsyntaxhighlight>
{{Out}}
Output of <langsyntaxhighlight lang=sh>wish br.wish 1809-02-12 1863-11-19</langsyntaxhighlight> - Lincoln's biorhythms at Gettysburg:
https://i.imgur.com/U2izZOM.png
 
=={{header|VBA}}==
{{trans|Wren}}
<langsyntaxhighlight lang=vb>Function Biorhythm(Birthdate As Date, Targetdate As Date) As String
 
'Jagged Array
Line 1,824:
Debug.Print ""
 
End Function</langsyntaxhighlight>
{{Out}}
<pre>
Line 1,848:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang=vlang>import time
import math
Line 1,903:
biorhythms(date_pair[0], date_pair[1])?
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,930:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang=ecmascript>import "/date" for Date
import "/fmt" for Fmt
 
Line 1,975:
["1809-02-12", "1863-11-19"] // correct DOB for Abraham Lincoln
]
for (datePair in datePairs) biorhythms.call(datePair[0], datePair[1])</langsyntaxhighlight>
 
{{out}}
10,327

edits