Biorhythms: Difference between revisions

no edit summary
No edit summary
Line 1,682:
Emotional day 14 : critical transition
Mental day 3 : 54.1% (up and rising, next peak 24.11.1863)
</pre>
 
=={{header|Vlang}}==
{{trans|Go}}
<lang vlang>import time
import math
const cycles = ["Physical day ", "Emotional day", "Mental day "]
const lengths = [23, 28, 33]
const quadrants = [
["up and rising", "peak"],
["up but falling", "transition"],
["down and falling", "valley"],
["down but rising", "transition"],
]
// Parameters assumed to be in YYYY-MM-DD format.
fn biorhythms(birth_date string, target_date string) ? {
bd := time.parse_iso8601(birth_date)?
td := time.parse_iso8601(target_date)?
days := int((td-bd).hours() / 24)
println("Born $birth_date, Target $target_date")
println("Day $days")
for i in 0..3 {
length := lengths[i]
cycle := cycles[i]
position := days % length
quadrant := position * 4 / length
mut percent := math.sin(2 * math.pi * f64(position) / f64(length))
percent = math.floor(percent*1000) / 10
mut descript := ""
if percent > 95 {
descript = " peak"
} else if percent < -95 {
descript = " valley"
} else if math.abs(percent) < 5 {
descript = " critical transition"
} else {
days_to_add := (quadrant+1)*length/4 - position
transition := td.add(time.hour * 24 * time.Duration(days_to_add))
trend := quadrants[quadrant][0]
next := quadrants[quadrant][1]
trans_str := transition.custom_format('YYYY-MM-DD')
descript = "${percent:5.1f}% ($trend, next $next $trans_str)"
}
println("$cycle ${position:2} : $descript")
}
println('')
}
fn main() {
date_pairs := [
["1943-03-09", "1972-07-11"],
["1809-01-12", "1863-11-19"],
["1809-02-12", "1863-11-19"], // correct DOB for Abraham Lincoln
]
for date_pair in date_pairs {
biorhythms(date_pair[0], date_pair[1])?
}
}</lang>
 
{{out}}
<pre>
Born 1943-03-09, Target 1972-07-11
Day 10717
Physical day 22 : -27.0% (down but rising, next transition 1972-07-12)
Emotional day 21 : valley
Mental day 25 : valley
 
Born 1809-01-12, Target 1863-11-19
Day 20034
Physical day 1 : 26.9% (up and rising, next peak 1863-11-23)
Emotional day 14 : critical transition
Mental day 3 : 54.0% (up and rising, next peak 1863-11-24)
 
Born 1809-02-12, Target 1863-11-19
Day 20003
Physical day 16 : -94.3% (down and falling, next valley 1863-11-20)
Emotional day 11 : 62.3% (up but falling, next transition 1863-11-22)
Mental day 5 : 81.4% (up and rising, next peak 1863-11-22)
</pre>
 
338

edits