-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
461 additions
and
442 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# Call me master of business | ||
|
||
## Calculate the most efficient way of dealing with enemy in HuBiao events | ||
|
||
**Enemy** : [num1, num2, num3, num4, num5] = $Y_{1-5}$ | ||
|
||
**Ours**: [num1, ... num5] = $X_{1-5}$ | ||
|
||
We want $X_{1-5}$ >= $Y_{1-5}$ by a rule of at three larger number in position wins. | ||
|
||
$Y_{1-5}$ is usually known (If we don't fight against others on purpose) | ||
|
||
While each number in $X$ is chosen from a list of number $\{x_1, x_2 ,... x_n\}$ . | ||
|
||
Our ***Objective*** is to minimize $\sum_{i=1\rightarrow5}X_i$ and make sure $X > Y$ at least at chance of percentage of **95*%***. | ||
# Call me DZG | ||
|
||
1. [劫镖计算](劫镖计算) | ||
|
||
1. 🌝根据对方的全部挚友数据,以及战斗力推算对方的可能阵容 | ||
2. 🌝根据推测的阵容,安排我方有$P_{pass}$以上通过率的最小战斗力和阵容 | ||
3. 🌑考虑出战的损耗值 | ||
4. 🌑多几个输出,可以按照不同的角度获得不同的阵容(花元宝的数量、战斗力总和值,方差值) | ||
|
||
2. [商铺统计](商铺统计) | ||
|
||
1. 🌗根据商铺街的数据分析最适合在哪里招募员工 | ||
2. 🌑根据商铺街的数据分析哪个商店值得庄园增加员工工效 | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# ignore office temp files | ||
~$* | ||
# ignore python cache files | ||
__pycache__/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Call me master of business | ||
|
||
## Calculate the most efficient way of dealing with enemy in HuBiao events | ||
|
||
**Enemy** : [num1, num2, num3, num4, num5] = $Y_{1-5}$ | ||
|
||
**Ours**: [num1, ... num5] = $X_{1-5}$ | ||
|
||
We want $X_{1-5}$ >= $Y_{1-5}$ by a rule of at three larger number in position wins. | ||
|
||
$Y_{1-5}$ is usually known (If we don't fight against others on purpose) | ||
|
||
While each number in $X$ is chosen from a list of number $\{x_1, x_2 ,... x_n\}$ . | ||
|
||
Our ***Objective*** is to minimize $\sum_{i=1\rightarrow5}X_i$ and make sure $X > Y$ at least at chance of percentage of **95*%***. |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
# 蒙特卡洛 方法 判断击落概率 | ||
|
||
from random import shuffle | ||
|
||
debug = False | ||
def judge(attack : list[int], defend : list[int]) -> int: | ||
# task: judge whether attack can defeat defend nums and return True or False | ||
|
||
# sub1: 判断大小是否一致 : 待完成 | ||
total = len(attack) | ||
# sub2: judge whether attack coud beat defend and return result | ||
win = 0 | ||
for i in range(len(attack)): | ||
win += (attack[i] > defend[i]) | ||
# return example | ||
# win lose -> result | ||
# 2 2 -> False. | ||
# 3 2 -> True | ||
return 1 if win > total/2 else 0 | ||
|
||
def test_cases_generator(originList : list[int]) -> list[int]: | ||
posNum = len(originList)-1 | ||
for (index, testNum) in enumerate(originList): | ||
newList = originList[:index] + originList[index:] | ||
# I couldn't write it out... ||<>..<>|| | ||
pass | ||
def cankill_brutal(attack : list[int], defend : list[int], testNum = 100, probability = 0.95): | ||
game_num = 0 | ||
win = 0 | ||
testCases = test_cases_generator(defend) | ||
for tsetCase in testCases: | ||
game_num += 1 | ||
win += judge(attack, testCases) | ||
if win >= probability * game_num: | ||
return True | ||
else: | ||
return False | ||
|
||
def cankill_montecarlo(attack : list[int], defend : list[int], testNum = 100, probability = 0.95, debug = False): | ||
if testNum <= 0: | ||
if debug == True: print("Invalid test number for mentekaluo") | ||
return False | ||
|
||
else: # testNum > 0 | ||
game_num = testNum | ||
win = 0 | ||
for i in range(testNum): | ||
shuffle(defend) | ||
if judge(attack, defend) == 0: | ||
if debug: | ||
print(f"You loose at {attack} vs {defend}") | ||
else: | ||
win += 1 | ||
# win += judge(attack, defend) | ||
if debug == True: | ||
print(f"\nWin time = {win}, probability of winning is {win/testNum}\n") | ||
if win >= probability * testNum: | ||
return True | ||
return False | ||
|
||
#test = False | ||
if __name__ == "__main__": | ||
test = True | ||
if test == True: | ||
print("can you kill", end = " ") | ||
# print(canKill_mentekaluo([5,5,5,3,1], [4,4,5,3,2])) | ||
print(cankill_montecarlo([364, 314, 229, 100, 100], [188, 195, 243, 217, 195])) | ||
print(cankill_montecarlo([161, 156, 142, 123, 100], [65, 133, 106, 85, 119])) | ||
print(cankill_montecarlo([199, 181, 172, 172, 144], [180, 188, 171, 148, 143])) | ||
# print(canKill_montecarlo([161, 156, 144, 123, 100], [135, 136, 118, 116, 103])) | ||
# print(canKill_montecarlo([199, 266,167, 196, 100], [188,195,185,163,195], testNum = 20000)) | ||
# print(canKill_montecarlo([199, 266,167, 196, 100], [156,144,150,150,153], testNum = 20000)) | ||
# print(canKill_montecarlo([123, 164,156, 164, 100], [156,144,150,150,153], testNum = 20000)) # actually 0.9's probability of winning | ||
print(cankill_montecarlo([364, 130,613, 546, 156], [217,238,249,267,323], testNum = 20000)) | ||
print(cankill_montecarlo([364, 546, 613, 314, 268], [1268,1062,340,257,229], testNum= 4000, debug=True, probability=0.59)) | ||
else: | ||
print("Test is not run") | ||
|
||
|
||
# 蒙特卡洛 方法 判断击落概率 | ||
|
||
from random import shuffle | ||
|
||
debug = False | ||
def judge(attack : list[int], defend : list[int]) -> int: | ||
# task: judge whether attack can defeat defend nums and return True or False | ||
|
||
# sub1: 判断大小是否一致 : 待完成 | ||
total = len(attack) | ||
# sub2: judge whether attack coud beat defend and return result | ||
win = 0 | ||
for i in range(len(attack)): | ||
win += (attack[i] > defend[i]) | ||
# return example | ||
# win lose -> result | ||
# 2 2 -> False. | ||
# 3 2 -> True | ||
return 1 if win > total/2 else 0 | ||
|
||
def test_cases_generator(originList : list[int]) -> list[int]: | ||
posNum = len(originList)-1 | ||
for (index, testNum) in enumerate(originList): | ||
newList = originList[:index] + originList[index:] | ||
# I couldn't write it out... ||<>..<>|| | ||
pass | ||
def cankill_brutal(attack : list[int], defend : list[int], testNum = 100, probability = 0.95): | ||
game_num = 0 | ||
win = 0 | ||
testCases = test_cases_generator(defend) | ||
for tsetCase in testCases: | ||
game_num += 1 | ||
win += judge(attack, testCases) | ||
if win >= probability * game_num: | ||
return True | ||
else: | ||
return False | ||
|
||
def cankill_montecarlo(attack : list[int], defend : list[int], testNum = 100, probability = 0.95, debug = False): | ||
if testNum <= 0: | ||
if debug == True: print("Invalid test number for mentekaluo") | ||
return False | ||
|
||
else: # testNum > 0 | ||
game_num = testNum | ||
win = 0 | ||
for i in range(testNum): | ||
shuffle(defend) | ||
if judge(attack, defend) == 0: | ||
if debug: | ||
print(f"You loose at {attack} vs {defend}") | ||
else: | ||
win += 1 | ||
# win += judge(attack, defend) | ||
if debug == True: | ||
print(f"\nWin time = {win}, probability of winning is {win/testNum}\n") | ||
if win >= probability * testNum: | ||
return True | ||
return False | ||
|
||
#test = False | ||
if __name__ == "__main__": | ||
test = True | ||
if test == True: | ||
print("can you kill", end = " ") | ||
# print(canKill_mentekaluo([5,5,5,3,1], [4,4,5,3,2])) | ||
print(cankill_montecarlo([364, 314, 229, 100, 100], [188, 195, 243, 217, 195])) | ||
print(cankill_montecarlo([161, 156, 142, 123, 100], [65, 133, 106, 85, 119])) | ||
print(cankill_montecarlo([199, 181, 172, 172, 144], [180, 188, 171, 148, 143])) | ||
# print(canKill_montecarlo([161, 156, 144, 123, 100], [135, 136, 118, 116, 103])) | ||
# print(canKill_montecarlo([199, 266,167, 196, 100], [188,195,185,163,195], testNum = 20000)) | ||
# print(canKill_montecarlo([199, 266,167, 196, 100], [156,144,150,150,153], testNum = 20000)) | ||
# print(canKill_montecarlo([123, 164,156, 164, 100], [156,144,150,150,153], testNum = 20000)) # actually 0.9's probability of winning | ||
print(cankill_montecarlo([364, 130,613, 546, 156], [217,238,249,267,323], testNum = 20000)) | ||
print(cankill_montecarlo([364, 546, 613, 314, 268], [1268,1062,340,257,229], testNum= 4000, debug=True, probability=0.59)) | ||
else: | ||
print("Test is not run") | ||
|
||
|
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
# template for reading xlsx file's first and second row to the end | ||
# reference : https://linuxhint.com/read-excel-file-python/#:~:text=The%20read_excel()%20function%20of,in%20the%20variable%20named%20data. | ||
import openpyxl | ||
|
||
# Define variable to load the wookbook | ||
wookbook = openpyxl.load_workbook("test.xlsx") | ||
|
||
# Define variable to read the active sheet: | ||
worksheet = wookbook.active | ||
|
||
# Iterate the loop to read the cell values | ||
names = list() | ||
values = list() | ||
|
||
|
||
for i in range(0, worksheet.max_row): | ||
for (j, col) in enumerate(worksheet.iter_cols(1, worksheet.max_column)): | ||
print(col[i].value, end="\t\t") | ||
if (i> 0) and (j == 0): | ||
names.append(col[i].value.strip("")) | ||
if (i> 0) and (j == 1): | ||
values.append(col[i].value) | ||
print('') | ||
|
||
print(names) | ||
print(values) | ||
|
||
for (i,name) in enumerate(names): | ||
print(f" The {i+1}th person is {name} with a value of {values[i]}") | ||
|
||
# test case results | ||
|
||
#Name OurData | ||
#小师妹 1016 | ||
#苗疆女 613 | ||
#李师师 546 | ||
#役使 364 | ||
#棋士 314 | ||
#西域女子 266 | ||
#将门女 199 | ||
#小乞丐 182 | ||
#绣娘 173 | ||
#丫鬟 172 | ||
#草原女孩 167 | ||
#采药女 164 | ||
#医师 161 | ||
#书香女 156 | ||
#针线女 144 | ||
#戏子 123 | ||
#卖伞女 100 | ||
#['小师妹', '苗疆女', '李师师', '役使', '棋士', '西域女子', '将门女', '小乞丐', '绣娘', '丫鬟', '草原女孩', '采药女', '医师', ' | ||
#书香女', '针线女', '戏子', '卖伞女'] | ||
#[1016, 613, 546, 364, 314, 266, 199, 182, 173, 172, 167, 164, 161, 156, 144, 123, 100] | ||
# The 1th person is 小师妹 with a value of 1016 | ||
# The 2th person is 苗疆女 with a value of 613 | ||
# The 3th person is 李师师 with a value of 546 | ||
# The 4th person is 役使 with a value of 364 | ||
# The 5th person is 棋士 with a value of 314 | ||
# The 6th person is 西域女子 with a value of 266 | ||
# The 7th person is 将门女 with a value of 199 | ||
# The 8th person is 小乞丐 with a value of 182 | ||
# The 9th person is 绣娘 with a value of 173 | ||
# The 10th person is 丫鬟 with a value of 172 | ||
# The 11th person is 草原女孩 with a value of 167 | ||
# The 12th person is 采药女 with a value of 164 | ||
# The 13th person is 医师 with a value of 161 | ||
# The 14th person is 书香女 with a value of 156 | ||
# The 15th person is 针线女 with a value of 144 | ||
# The 16th person is 戏子 with a value of 123 | ||
# The 17th person is 卖伞女 with a value of 100 | ||
# template for reading xlsx file's first and second row to the end | ||
# reference : https://linuxhint.com/read-excel-file-python/#:~:text=The%20read_excel()%20function%20of,in%20the%20variable%20named%20data. | ||
import openpyxl | ||
|
||
# Define variable to load the wookbook | ||
wookbook = openpyxl.load_workbook("test.xlsx") | ||
|
||
# Define variable to read the active sheet: | ||
worksheet = wookbook.active | ||
|
||
# Iterate the loop to read the cell values | ||
names = list() | ||
values = list() | ||
|
||
|
||
for i in range(0, worksheet.max_row): | ||
for (j, col) in enumerate(worksheet.iter_cols(1, worksheet.max_column)): | ||
print(col[i].value, end="\t\t") | ||
if (i> 0) and (j == 0): | ||
names.append(col[i].value.strip("")) | ||
if (i> 0) and (j == 1): | ||
values.append(col[i].value) | ||
print('') | ||
|
||
print(names) | ||
print(values) | ||
|
||
for (i,name) in enumerate(names): | ||
print(f" The {i+1}th person is {name} with a value of {values[i]}") | ||
|
||
# test case results | ||
|
||
#Name OurData | ||
#小师妹 1016 | ||
#苗疆女 613 | ||
#李师师 546 | ||
#役使 364 | ||
#棋士 314 | ||
#西域女子 266 | ||
#将门女 199 | ||
#小乞丐 182 | ||
#绣娘 173 | ||
#丫鬟 172 | ||
#草原女孩 167 | ||
#采药女 164 | ||
#医师 161 | ||
#书香女 156 | ||
#针线女 144 | ||
#戏子 123 | ||
#卖伞女 100 | ||
#['小师妹', '苗疆女', '李师师', '役使', '棋士', '西域女子', '将门女', '小乞丐', '绣娘', '丫鬟', '草原女孩', '采药女', '医师', ' | ||
#书香女', '针线女', '戏子', '卖伞女'] | ||
#[1016, 613, 546, 364, 314, 266, 199, 182, 173, 172, 167, 164, 161, 156, 144, 123, 100] | ||
# The 1th person is 小师妹 with a value of 1016 | ||
# The 2th person is 苗疆女 with a value of 613 | ||
# The 3th person is 李师师 with a value of 546 | ||
# The 4th person is 役使 with a value of 364 | ||
# The 5th person is 棋士 with a value of 314 | ||
# The 6th person is 西域女子 with a value of 266 | ||
# The 7th person is 将门女 with a value of 199 | ||
# The 8th person is 小乞丐 with a value of 182 | ||
# The 9th person is 绣娘 with a value of 173 | ||
# The 10th person is 丫鬟 with a value of 172 | ||
# The 11th person is 草原女孩 with a value of 167 | ||
# The 12th person is 采药女 with a value of 164 | ||
# The 13th person is 医师 with a value of 161 | ||
# The 14th person is 书香女 with a value of 156 | ||
# The 15th person is 针线女 with a value of 144 | ||
# The 16th person is 戏子 with a value of 123 | ||
# The 17th person is 卖伞女 with a value of 100 |
Oops, something went wrong.