-
Notifications
You must be signed in to change notification settings - Fork 1
/
world_war_computing
83 lines (71 loc) · 1.75 KB
/
world_war_computing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
a=( 3 10 15 32 50 75 100 )
b=( 42529 143970 213095 455280 706500 1065000 1512000 )
c=( 1000 6500 16500 56000 270000 500000 700000 1200000 1400000 )
d=( 2780 13024 37760 142400 573000 1017000 1500000 2600000 3120000 )
function compute() {
if [[ "$1" == DEF ]]
then
local m=( "${b[@]}" )
local n=( "${a[@]}" )
local LIMIT=${#a[@]}
for ((k=0; k < $LIMIT ; k++))
do
local n1[$k]=`expr ${n[$k]}`
done
else
local LIMIT=${#c[@]}
local m=( "${d[@]}" )
local n=( "${c[@]}" )
local n1=( "${c[@]}" )
for ((k=0; k < $LIMIT ; k++))
do
local m[$k]=`expr ${m[$k]} \* 1000`
done
fi
for ((k=0; k < $LIMIT ; k++))
do
local PRE[$k]=`expr "${m[$k]}" / "${n1[$k]}"`
done
local MIN_PRE=${PRE[0]}
for ((k=1; k < $LIMIT ; k++))
do
if [ ${PRE[$k]} -lt $MIN_PRE ]
then
MIN_PRE=${PRE[$k]}
fi
done
for ((k=0; k < $LIMIT ; k++))
do
if [ $MIN_PRE -eq ${PRE[$k]} ]
then
echo -e "$1: ${n[$k]} \tPrice ${m[$k]} \t P ${PRE[$k]}"
local K_MIN=$k
fi
done
if [ $K_MIN -eq "0" ]
then
local MIN_POS=${PRE[1]}
else
local MIN_POS=${PRE[0]}
fi
for ((k=0; k < $LIMIT ; k++))
do
if [ $k -ne $K_MIN ]
then
if [ ${PRE[$k]} -lt $MIN_POS ]
then
MIN_POS=${PRE[$k]}
fi
fi
done
for ((k=0; k < $LIMIT ; k++))
do
if [ $MIN_POS -eq ${PRE[$k]} ]
then
echo -e "Second: ${n[$k]} \tPrice ${m[$k]} \t P ${PRE[$k]}"
fi
done
}
compute DEF
compute POW