Skip to content

Instantly share code, notes, and snippets.

@Kazanir
Created July 29, 2016 23:48
Show Gist options
  • Save Kazanir/19bafe874db9bbe12169ecfef7ef5905 to your computer and use it in GitHub Desktop.
Save Kazanir/19bafe874db9bbe12169ecfef7ef5905 to your computer and use it in GitHub Desktop.
Artifact power MS/OS breakdown calculator
<?hh // strict
class ArtifactPower {
public Map<int, int> $costs = Map {
1 => 100,
2 => 400,
3 => 725,
4 => 1075,
5 => 1450,
6 => 1850,
7 => 2275,
8 => 2725,
9 => 3250,
10 => 3875,
11 => 4625,
12 => 5500,
13 => 6500,
14 => 13340,
15 => 22170,
16 => 33450,
17 => 47850,
18 => 66470,
19 => 90470,
20 => 121070,
21 => 160590,
22 => 211470,
23 => 276270,
24 => 358770,
25 => 464050,
26 => 602700,
27 => 785480,
28 => 1026350,
29 => 1341870,
30 => 1759430,
31 => 2305430,
32 => 3023630,
33 => 3970290,
34 => 5216130,
35 => 6851330,
36 => 8766330,
37 => 10776330,
38 => 12886330,
39 => 15101330,
40 => 17426330,
41 => 19866330,
42 => 22426330,
43 => 25116330,
44 => 27941330,
45 => 30906330,
46 => 34021330,
47 => 37291330,
48 => 40726330,
49 => 44331330,
50 => 48116330,
51 => 52091330,
52 => 56266330,
53 => 60651330,
54 => 65256330,
};
public function getCost(int $level): int {
if ($level < 1 || $level > 54) {
throw new Exception("Artifact power level out of bounds.");
}
return $this->costs[$level];
}
public function getMaxLevel(int $cost): int {
$matches = $this->costs->filter($c ==> $c <= $cost);
ksort($matches);
return $matches->lastKey() ?: 0;
}
public function getPairs(int $points): Vector<Pair<int, int>> {
$mainSpecLevel = $this->getMaxLevel($points);
$maxOffSpecLevel = 0;
$results = Vector {};
do {
$offSpecPoints = $points - $this->getCost($mainSpecLevel);
$offSpecLevel = $this->getMaxLevel($offSpecPoints);
if ($offSpecLevel > $maxOffSpecLevel) {
$results[] = Pair { $mainSpecLevel, $offSpecLevel };
$maxOffSpecLevel = $offSpecLevel;
}
} while (--$mainSpecLevel > $maxOffSpecLevel);
return $results;
}
public function printResults(Vector<Pair<int, int>> $results): void {
print "-----------" . PHP_EOL;
print "| MS | OS |" . PHP_EOL;
print "-----------" . PHP_EOL;
print implode(PHP_EOL, $results->map($r ==> '| ' . str_pad($r[0], 2, ' ', STR_PAD_LEFT) . ' | ' . str_pad($r[1], 2, ' ', STR_PAD_LEFT) . ' |')) . PHP_EOL;
print "-----------" . PHP_EOL;
}
public function processPoints(array<int> $totals): void {
foreach ($totals as $p) {
$pairs = $this->getPairs($p);
print "$p Points:" . PHP_EOL;
$this->printResults($pairs);
}
}
}
<?php
include 'ArtifactPower.class.php';
$ap = new ArtifactPower();
$points = array(
80000,
110000,
145000,
200000,
266000,
360000,
495000,
675000,
920000,
1247000,
1577000,
1917000,
2257000,
2597000,
2937000,
);
$ap->processPoints($points);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment