-
-
Save rightfold/b47dc7b613ce481876ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
constant FACTORS = do { | |
my %factors = | |
s => 1, | |
m => 60, | |
h => 3600, | |
d => 86400, | |
y => 31536000, | |
; | |
for %factors.keys.eager { | |
%factors{"Y$_"} = 1000000000000000000000000 * %factors{$_}; | |
%factors{"Z$_"} = 1000000000000000000000 * %factors{$_}; | |
%factors{"E$_"} = 1000000000000000000 * %factors{$_}; | |
%factors{"P$_"} = 1000000000000000 * %factors{$_}; | |
%factors{"T$_"} = 1000000000000 * %factors{$_}; | |
%factors{"G$_"} = 1000000000 * %factors{$_}; | |
%factors{"M$_"} = 1000000 * %factors{$_}; | |
%factors{"k$_"} = 1000 * %factors{$_}; | |
%factors{"m$_"} = 0.001 * %factors{$_}; | |
%factors{"u$_"} = 0.000001 * %factors{$_}; | |
%factors{"n$_"} = 0.000000001 * %factors{$_}; | |
%factors{"p$_"} = 0.000000000001 * %factors{$_}; | |
%factors{"a$_"} = 0.000000000000000001 * %factors{$_}; | |
%factors{"z$_"} = 0.000000000000000000001 * %factors{$_}; | |
%factors{"y$_"} = 0.000000000000000000000001 * %factors{$_}; | |
} | |
%factors; | |
}; | |
class Isotope { | |
has Str:D $.isotope; | |
has Real:D $.half-life; | |
method parse(Cool:D $line) { | |
my $isotope = ($line.substr(11, 5) // '').trim; | |
my $half-life-str = ($line.substr(61, 7) // '').trim; | |
my $half-life-unit = ($line.substr(69, 2) // '').trim; | |
unless $isotope ~~ /^\w+$/ | |
&& $half-life-str ~~ /^\d+(\.\d+)?$/ | |
&& (FACTORS{$half-life-unit}:exists) { | |
return Nil; | |
} | |
my $half-life = $half-life-str * FACTORS{$half-life-unit}; | |
Isotope.new(isotope => $isotope, half-life => $half-life); | |
} | |
} | |
for $*ARGFILES.lines { | |
my $isotope = Isotope.parse($_); | |
next unless defined $isotope; | |
say sprintf("%s\t%.40f", $isotope.isotope, $isotope.half-life); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment