Biorhythms: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Raku}}: fix envar default birthday) |
||
Line 979: | Line 979: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang raku>#!/usr/bin/env raku |
<lang raku>#!/usr/bin/env raku |
||
unit sub MAIN($birthday=%*ENV<BIRTHDAY>, $date = Date.today()) { |
|||
my %cycles = ( :23Physical, :28Emotional, :33Mental ); |
my %cycles = ( :23Physical, :28Emotional, :33Mental ); |
||
my @quadrants = [ ('up and rising', 'peak'), |
my @quadrants = [ ('up and rising', 'peak'), |
||
Line 985: | Line 987: | ||
('down but rising', 'transition') ]; |
('down but rising', 'transition') ]; |
||
if !$birthday { |
|||
if !$birthday { |
|||
die "Birthday not specified.\n" ~ |
die "Birthday not specified.\n" ~ |
||
"Supply --birthday option or set \$BIRTHDAY in environment.\n"; |
"Supply --birthday option or set \$BIRTHDAY in environment.\n"; |
||
} |
|||
my ($bday, $target) = ($birthday, $date).map: { Date.new($_) }; |
|||
my $days = $target - $bday; |
|||
say "Day $days:"; |
|||
for %cycles.sort(+*.value)».kv -> ($label, $length) { |
|||
my $position = $days % $length; |
my $position = $days % $length; |
||
my $quadrant = floor($position / $length * 4); |
my $quadrant = floor($position / $length * 4); |
||
Line 1,001: | Line 1,002: | ||
my $description; |
my $description; |
||
if $percentage > 95 { |
if $percentage > 95 { |
||
$description = 'peak'; |
$description = 'peak'; |
||
} elsif $percentage < -95 { |
} elsif $percentage < -95 { |
||
$description = 'valley'; |
$description = 'valley'; |
||
} elsif abs($percentage) < 5 { |
} elsif abs($percentage) < 5 { |
||
$description = 'critical transition' |
$description = 'critical transition' |
||
} else { |
} else { |
||
my $transition = $target + floor(($quadrant + 1)/4 * $length) - $position; |
my $transition = $target + floor(($quadrant + 1)/4 * $length) - $position; |
||
my ($trend, $next) = @quadrants[$quadrant]; |
my ($trend, $next) = @quadrants[$quadrant]; |
||
$description = "$percentage% ($trend, next $next $transition)"; |
$description = "$percentage% ($trend, next $next $transition)"; |
||
} |
} |
||
say "$label day $position: $description"; |
say "$label day $position: $description"; |