Download app1/code_block.py from debo106/llm: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/debo106/llm/resolve/main/app1/code_block.py
- Command line
-
hf download hf://spaces/debo106/llm/app1/code_block.py
-
curl -L -o code_block.py https://huggingface.co/spaces/debo106/llm/resolve/main/app1/code_block.py
1.56 kB
| ```python | |
| import pandas as pd | |
| import itertools | |
| # 约束条件 | |
| SUM_CONSTRAINT = 100 | |
| MIN_NON_ZERO = 2 | |
| MAX_ZERO = 5 | |
| MIN_SUM_X3_X4_X8_X9 = 35 | |
| MAX_SUM_X3_X4_X8_X9 = 80 | |
| RANGE = range(0, 41, 10) # x1~x9的最小值和最大值范围,步长为10 | |
| # 生成可能的组合 | |
| def cartesian_product(*arrays): | |
| return list(itertools.product(*arrays)) | |
| # 检查组合是否满足约束条件 | |
| def is_valid_combination(combination): | |
| # 条件1: x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 = 100 | |
| if sum(combination) != SUM_CONSTRAINT: | |
| return False | |
| # 条件2: 至少两个不为0,至多5个为0 | |
| non_zero_count = sum(1 for x in combination if x != 0) | |
| if non_zero_count < MIN_NON_ZERO or non_zero_count > 9 - MAX_ZERO: | |
| return False | |
| # 条件3: 35 <= x3 + x4 + x8 + x9 <= 80 | |
| sum_x3_x4_x8_x9 = sum(combination[2:6:3]) # x3, x4, x8, x9 | |
| if not MIN_SUM_X3_X4_X8_X9 <= sum_x3_x4_x8_x9 <= MAX_SUM_X3_X4_X8_X9: | |
| return False | |
| # 条件4: x1, x2, x3, x4, x5, x6, x7, x8, x9的最小值为0,最大值为40,步长为10 | |
| for x in combination: | |
| if x not in RANGE: | |
| return False | |
| return True | |
| # 生成所有可能的组合 | |
| all_ranges = [RANGE for _ in range(9)] | |
| all_combinations = cartesian_product(*all_ranges) | |
| # 过滤符合条件的组合 | |
| valid_combinations = [combination for combination in all_combinations if is_valid_combination(combination)] | |
| # 创建DataFrame | |
| df = pd.DataFrame(valid_combinations, columns=['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9']) | |
| print(df) | |
| ``` |