Data update

This commit is contained in:
Ingy döt Net 2024-11-04 20:28:54 -08:00
parent 52a6ef48dd
commit 157b70a810
604 changed files with 14253 additions and 2100 deletions

View file

@ -0,0 +1,76 @@
BEGIN # biorythms #
# code from the Day of the week of Christmas and New Year task #
[]STRING day name =
[]STRING( "SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI" )[ AT 0 ];
PROC day of week = ( INT y, m, d )INT:
BEGIN
INT mm := m;
INT yy := y;
IF mm <= 2 THEN
mm +:= 12;
yy -:= 1
FI;
INT j = yy OVER 100;
INT k = yy MOD 100;
( d + ( ( mm + 1 ) * 26 ) OVER 10 + k + k OVER 4 + j OVER 4 + 5 * j ) MOD 7
END # day of week # ;
# end code from the Day of the week of Christmas and New Year task #
# code from the days between dates task #
PROC gregorian = ( INT y, m, d )INT:
BEGIN
INT n = ( m + 9 ) - ( ( ( m + 9 ) OVER 12 ) * 12 );
INT w = y - ( n OVER 10 );
( 365 * w ) + ( w OVER 4 ) - ( w OVER 100 ) + ( w OVER 400 )
+ ( ( ( n * 306 ) + 5 ) OVER 10 ) + ( d - 1 )
END # gregorian # ;
# end code from the days between dates task #
BEGIN # main routine - translated from the Fortran sample's main program #
PROC double line = VOID: print( ( "=" * 75, newline ) );
PROC in range = ( REAL v, INT low, high )INT:
IF v < low THEN low ELIF v > high THEN high ELSE ENTIER v FI;
REAL pi2 = pi * 2;
INT byear, bmon, bday, tyear, tmon, tday, nday;
print( ( "ENTER YOUR BIRTHDAY YYYY MM DD: " ) );
read( ( byear, bmon, bday ) );
print( ( "ENTER START DATE YYYY MM DD: " ) );
read( ( tyear, tmon, tday ) );
print( ( "ENTER NUMBER OF DAYS TO PLOT : " ) );
read( ( nday ) );
INT jd0 = gregorian( tyear, 1, 1 );
INT jd1 = gregorian( byear, bmon, bday );
INT jd2 := gregorian( tyear, tmon, tday );
INT dob = day of week( byear, bmon, bday );
INT dow := day of week( tyear, tmon, tday );
double line;
print( ( "YOU WERE BORN ON A (", day name[ dob MOD 7 ], ") YOU WERE " ) );
print( ( whole( jd2 - jd1, 0 ), " DAYS OLD ON THE START DATE.", newline ) );
print( ( "-1", 31 * " ", "0", 30 * " ", "+1 DOY", newline ) );
TO nday DO
INT dif = jd2 - jd1;
INT phy = in range( 3.3e1+3.2e1*sin( pi2 * dif / 2.3e1 ), 1, 65 );
INT emd = in range( 3.3e1+3.2e1*sin( pi2 * dif / 2.8e1 ), 1, 65 );
INT men = in range( 3.3e1+3.2e1*sin( pi2 * dif / 3.3e1 ), 1, 65 );
STRING g row := 65 * IF day name[ dow ] = "SUN" THEN "." ELSE " " FI;
g row[ 1 ] := "|";
g row[ 17 ] := ":";
g row[ 33 ] := "|";
g row[ 49 ] := ":";
g row[ 65 ] := "|";
g row[ phy ] := "P";
g row[ emd ] := "E";
g row[ men ] := "M";
IF phy = emd OR phy = men THEN g row[ phy ] := "*" FI;
IF emd = men THEN g row[ emd ] := "*" FI;
print( ( " ", g row, " ", day name[ dow ], " ", whole( jd2 - jd0 + 1, -3 ), newline ) );
jd2 +:= 1;
dow +:= 1 MODAB 7
OD;
double line
END
END

View file

@ -2,7 +2,7 @@
Biorhythms task for Rosetta Code
https://rosettacode.org/wiki/Biorhythms
Translated from FreeBasic to FutureBasic
Translated from FreeBASIC to FutureBasic
Rich Love May 24, 2024
Oct 16, 2024 fixed the percentage amounts

View file

@ -6,7 +6,7 @@ Module Biorhythms {
date bioDay="1972-07-11", transition
for k=1 to 1
long Days=bioDay-birth
Print "Day "+Days+":"
Print "Day "+(bioDay)+":"
string frm="{0:-20} : {1}", pword, dfmt="YYYY-MM-DD"
long position, percentage, length, targetday

View file

@ -0,0 +1,63 @@
use chrono::{NaiveDate, ParseError, TimeDelta};
use num_traits::float::FloatConst;
const PHYSICAL_WAVE: i64 = 23;
const EMOTIONAL_WAVE: i64 = 28;
const MENTAL_WAVE: i64 = 33;
const CYCLES: [&str; 3] = ["Physical day ", "Emotional day", "Mental day "];
const LENGTHS: [i64; 3] = [PHYSICAL_WAVE, EMOTIONAL_WAVE, MENTAL_WAVE];
const QUADRANTS: [[&str; 2]; 4] = [
["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: &str, target_date: &str) -> Result<i64, ParseError> {
let bd = NaiveDate::parse_from_str(birth_date, "%Y-%m-%d")?;
let td = NaiveDate::parse_from_str(target_date, "%Y-%m-%d")?;
let days = (td - bd).num_days();
println!("Born {}, Target {}", birth_date, target_date);
println!("Day {}:", days);
for i in 0..3 {
let length = LENGTHS[i];
let cycle = CYCLES[i];
let position = days % length;
let quadrant: usize = (4 * position as usize) / length as usize;
let mut percent = f64::sin(2. * f64::PI() * position as f64 / length as f64);
percent = percent * 100.0;
let description: String;
if percent > 95. {
description = " peak".to_owned();
} else if percent < -95. {
description = " valley".to_owned();
} else if percent.abs() < 5. {
description = " critical transition".to_owned();
} else {
let days_to_add = (quadrant as i64 + 1) * length / 4 - position;
let transition = td + TimeDelta::days(days_to_add);
let trend = QUADRANTS[quadrant][0];
let next = QUADRANTS[quadrant][1];
description = format!("{:5.1}% ({}, next {} {})", percent, trend, next, transition);
}
println!("{} {:>2} : {}", cycle, position, description);
}
println!();
Ok(0)
}
fn main() {
let 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 {
match biorhythms(date_pair[0], date_pair[1]) {
Err(_) => println!("Error in biorhythms function parsing {:?}", date_pair),
_ => {}
}
}
}