Created
January 3, 2013 15:24
-
-
Save anonymous/4444255 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
use v6; | |
my %items = | |
'Caldari Fuel Block' => { | |
price => 13231.99, | |
value => 12866.26, | |
stack_size => 40, | |
components => '8 Coolant, 4 Enriched Uranium, 158 Heavy Water, 158 Liquid Ozone, 4 Mechanical Parts, 420 Nitrogen Isotopes, 21 Oxygen, 1 Robotics' | |
}, | |
'Coolant' => { | |
price => 9800, | |
value => 9699.06, | |
components => False | |
}, | |
'Enriched Uranium' => { | |
price => 10998.96, | |
value => 10443.02, | |
components => False | |
}, | |
'Heavy Water' => { | |
price => 88.95, | |
value => 83.23, | |
components => False | |
}, | |
'Liquid Ozone' => { | |
price => 398.00, | |
value => 305.00, | |
components => False | |
}, | |
'Mechanical Parts' => { | |
price => 10470.99, | |
value => 10075.03, | |
components => False | |
}, | |
'Nitrogen Isotopes' => { | |
price => 480.99, | |
value => 451.02, | |
components => False | |
}, | |
'Oxygen' => { | |
price => 377.81, | |
value => 364.03, | |
components => False | |
}, | |
'Robotics' => { | |
price => 76489.77, | |
value => 74116.06, | |
components => False | |
}, | |
'Customs Office Gantry' => { | |
price => 66000000, | |
value => 55000000, | |
components => '1 Capital Construction Parts, 5 Integrity Response Drones, 10 Nano-Factory, 10 Organic Mortar Applicators, 14 Sterile Conduits' | |
}, | |
'Capital Construction Parts' => { | |
price => 10499998.98, | |
value => 9050101.05, | |
}, | |
'Integrity Response Drones' => { | |
price => 1549989.99, | |
value => 1524000.01, | |
}, | |
'Nano-Factory' => { | |
price => 748000, | |
value => 713000, | |
}, | |
'Organic Mortar Applicators' => { | |
price => 730000, | |
value => 682000, | |
}, | |
'Sterile Conduits' => { | |
price => 891890.97, | |
value => 802000.04, | |
} | |
sub untangle_components_string(Str $s){ | |
my @a = $s.split(/',' \s*/); | |
return gather for @a -> $m { | |
$m ~~ /(\d+) \s+ (<[A..Z a..z \s \-]>+)/; | |
# say "$0: $1"; | |
die "cannot find $1" unless %items{$1.Str}; | |
take $0.Int; take %items{$1.Str}; | |
} | |
} | |
sub untangle_components(%item){ | |
return if %item<components> ~~ List; | |
%item<components> = untangle_components_string(%item<components>); | |
} | |
sub value_by_price(%item){ | |
untangle_components(%item); | |
my Num $sum = 0e0; | |
for %item<components> -> $k, $v { | |
$sum += $k * $v<price>; | |
} | |
return $sum / %item<stack_size> if %item<stack_size>; | |
return $sum; | |
} | |
sub value_by_value(%item){ | |
untangle_components(%item); | |
my Num $sum = 0e0; | |
for %item<components> -> $k, $v { | |
$sum += $k * $v<value>; | |
} | |
return $sum / %item<stack_size> if %item<stack_size>; | |
return $sum; | |
} | |
my Hash:D \caldari-fuel-block = %items{'Caldari Fuel Block'}; | |
my Hash:D \customs-office-gantry = %items{'Customs Office Gantry'}; | |
sub shopping_list(%item, :$amount is copy) { | |
$amount /= %item<stack_size> || 1; | |
gather for %item<components>.list -> $k, $v { | |
my $name = %items.invert.hash.{$v}; | |
take [$name, $amount * $k]; | |
} | |
} | |
untangle_components(caldari-fuel-block); | |
say caldari-fuel-block<components>[0]; | |
for caldari-fuel-block<components>[0,1] -> $k, $v { | |
say $k, $v; | |
} | |
for caldari-fuel-block<components>[0..*] -> $k, $v { | |
say $k, $v; | |
} | |
# HERE BE DRAGONS! | |
for caldari-fuel-block<components> -> $k, $v { | |
say $k, $v; | |
} | |
exit 0; | |
say "\nCaldari Fuel Block"; | |
say value_by_price(caldari-fuel-block); | |
say value_by_value(caldari-fuel-block); | |
say (shopping_list caldari-fuel-block, amount => 196250).join("\n"); | |
say "\nCustoms Office Gantry"; | |
say value_by_price(customs-office-gantry); | |
say value_by_value(customs-office-gantry); | |
say (shopping_list customs-office-gantry, amount => 66).join("\n"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment