Created
July 13, 2017 13:35
-
-
Save gedex/8ae51a682114befe3311feb0f188adbd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"flag" | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
var service = flag.String("service", "globalvalue", "service name") | |
// Key is zone and value is another map where key is service name value is | |
// array of 4 elements where values are described as follows: | |
// | |
// 0) Start price | |
// 1) Incremental value to the price addition when index is 0..3 | |
// 2) Incremental value to the price addition when index is 3..9 | |
// 2) Incremental value to the price addition when index is 9..20 | |
var magic = map[int]map[string][4]int{ | |
4: { | |
"globalvalue": [4]int{965, 120, 95, 40}, | |
"globalpriority": [4]int{2965, 125, 100, 40}, | |
"globalexpress": [4]int{5195, 255, 245, 275}, | |
}, | |
5: { | |
"irelandexpress": [4]int{1649, 0, 0, 0}, | |
"globalvalue": [4]int{1668, 240, 240, 102}, | |
"globalpriority": [4]int{3048, 252, 252, 108}, | |
"globalexpress": [4]int{4746, 246, 366, 168}, | |
}, | |
6: { | |
"globalvalue": [4]int{2244, 228, 216, 96}, | |
"globalpriority": [4]int{3384, 228, 222, 96}, | |
"globalexpress": [4]int{4302, 402, 330, 204}, | |
}, | |
7: { | |
"globalvalue": [4]int{2034, 60, 252, 198}, | |
"globalpriority": [4]int{3546, 192, 210, 150}, | |
"globalexpress": [4]int{4428, 354, 414, 312}, | |
}, | |
8: { | |
"globalvalue": [4]int{2562, 228, 198, 156}, | |
"globalpriority": [4]int{3852, 210, 228, 186}, | |
"globalexpress": [4]int{4758, 378, 306, 306}, | |
}, | |
9: { | |
"globalvalue": [4]int{2682, 324, 264, 222}, | |
"globalpriority": [4]int{4176, 318, 270, 228}, | |
"globalexpress": [4]int{5196, 462, 738, 498}, | |
}, | |
10: { | |
"globaleconomy": [4]int{2445, 250, 635, 365}, | |
"globalvalue": [4]int{2740, 250, 635, 365}, | |
"globalpriority": [4]int{4435, 250, 640, 370}, | |
"globalexpress": [4]int{5200, 495, 395, 420}, | |
}, | |
11: { | |
"globaleconomy": [4]int{3150, 615, 600, 450}, | |
"globalvalue": [4]int{3420, 615, 600, 450}, | |
"globalpriority": [4]int{4700, 590, 590, 450}, | |
"globalexpress": [4]int{6305, 650, 565, 465}, | |
}, | |
12: { | |
"globaleconomy": [4]int{3300, 705, 705, 640}, | |
"globalvalue": [4]int{3535, 705, 705, 640}, | |
"globalpriority": [4]int{5955, 685, 680, 610}, | |
"globalexpress": [4]int{7195, 865, 800, 620}, | |
}, | |
} | |
func main() { | |
flag.Parse() | |
var out string | |
for z := 4; z <= 12; z++ { | |
if m, ok := magic[z][*service]; !ok { | |
continue | |
} else { | |
out += dump(z, m) | |
} | |
} | |
fmt.Println(out) | |
} | |
func dump(z int, m [4]int) string { | |
out := "" | |
weight := 500 | |
price := m[0] | |
var prices [20][3]int | |
for i := 0; i < 20; i++ { | |
prices[i] = [3]int{weight, price, len(strconv.Itoa(weight))} | |
price = nextprice(i, price, m, z) | |
weight += 500 | |
} | |
maxw := len(strconv.Itoa(prices[19][0])) | |
var pad string | |
out += fmt.Sprintf("'%d' => array(\n", z) | |
for i := 0; i < 20; i++ { | |
pad = strings.Repeat(" ", maxw-prices[i][2]) | |
out += fmt.Sprintf("\t%d%s => %d,\n", prices[i][0], pad, prices[i][1]) | |
} | |
out += fmt.Sprint("),\n") | |
return out | |
} | |
func nextprice(i, price int, m [4]int, z int) int { | |
if "irelandexpress" == *service { | |
switch { | |
case i >= 3 && i < 9: | |
return 1748 | |
case i >= 9: | |
return 2090 | |
} | |
} | |
switch { | |
case i < 3: | |
price = price + m[1] | |
case i >= 3 && i < 9: | |
price = price + m[2] | |
case i >= 9: | |
price = price + m[3] | |
} | |
return price | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment