Skip to content

Instantly share code, notes, and snippets.

@t0saki
Last active March 26, 2025 09:04
Show Gist options
  • Save t0saki/e9d1c589270451bd2589a972b436a053 to your computer and use it in GitHub Desktop.
Save t0saki/e9d1c589270451bd2589a972b436a053 to your computer and use it in GitHub Desktop.
选择xyz域名
from tqdm import tqdm
def score_number(num_str):
"""
对6位数字字符串进行评分:
1. 相邻重复位数:每遇到相邻相同的数字,得分为重复个数的平方
2. 数字6、8、9:每出现一个加0.5分
3. 不同数字数量:奖励为 6 - (不同数字的数量),乘以0.5
4. 数字4:每出现一个扣0.5分
5. abcabc 模式:
- 如果前3位与后3位相同,且该三位组合在特殊组合字典中,则加上字典中对应的分值(例如 "985": 10)
- 否则若满足 abcabc 模式,则加3分
6. aabbcc 模式:如果数字按两两成组(即第1、2位相同,第3、4位相同,第5、6位相同),额外加3分
7. 连续数字奖励:在数字中寻找连续递增的序列(如123、4567),
如果连续数字长度>=3,则奖励 (连续长度-2)*3 分
8. abccba模式奖励:如果数字整体为回文(即正序等于倒序),额外奖励5分
"""
# 计算相邻重复位数得分:重复个数的平方
rep_count = sum(1 for i in range(1, len(num_str))
if num_str[i] == num_str[i-1])
rep_score = rep_count ** 2
# 统计数字6,8,9的个数
count_689 = sum(1 for ch in num_str if ch in "0689")
# 不同数字越少越好,奖励设为 6 - (不同数字的数量)
unique_digits = len(set(num_str))
unique_bonus = 6 - unique_digits
# 数字4扣分,每个4扣0.5分
count_4 = num_str.count("4")
# aabbcc模式 bonus:判断每两位是否相同
bonus_aabbcc = 3 if (num_str[0] == num_str[1] and num_str[2]
== num_str[3] and num_str[4] == num_str[5]) else 0
# 特殊组合字典,存储需要额外加分的特殊组合及对应的分值
special_combos = {
"985": 6,
"211": 6,
"114": 6,
"514": 6,
"996": 6,
"648": 6,
}
bonus_special = special_combos.get(num_str[:3], 0) + \
special_combos.get(num_str[3:], 0)
# abcabc模式 bonus:判断前3位与后3位是否相同
if num_str[:3] == num_str[3:]:
if num_str[:3] in special_combos:
bonus_abcabc = special_combos[num_str[:3]]
else:
bonus_abcabc = 3
else:
bonus_abcabc = 0
# 连续数字奖励:寻找数字中连续递增的序列(例如 123 或 4567)
max_consecutive = 1
current = 1
for i in range(1, len(num_str)):
# 若当前数字正好等于前一个数字+1,则为连续递增
if int(num_str[i]) == int(num_str[i-1]) + 1:
current += 1
else:
if current > max_consecutive:
max_consecutive = current
current = 1
max_consecutive = max(max_consecutive, current)
bonus_consecutive = (max_consecutive - 2) * \
3 if max_consecutive >= 3 else 0
# 额外加分:如果连续序列从开头或者延伸到结尾,则额外加3分(各自单独计算)
bonus_leading = 0
lead_length = 1
for i in range(1, len(num_str)):
if int(num_str[i]) == int(num_str[i-1]):
lead_length += 1
else:
break
if lead_length >= 3:
bonus_leading = 8
bonus_trailing = 0
trail_length = 1
for i in range(len(num_str)-1, 0, -1):
if int(num_str[i]) == int(num_str[i-1]):
trail_length += 1
else:
break
if trail_length >= 3:
bonus_trailing = 8
bonus_consecutive += bonus_leading + bonus_trailing
# abccba模式奖励:判断整个数字是否为回文(即正序==倒序)
bonus_abccba = 5 if num_str == num_str[::-1] else 0
# 计算总分,各项权重调整如下:
total_score = (
rep_score * 2 +
count_689 * 0.5 +
unique_bonus * 0.5 -
count_4 * 0.5 +
bonus_special +
bonus_abcabc +
bonus_aabbcc +
bonus_consecutive +
bonus_abccba
)
return total_score
def main():
# 假设域名存放在 download.txt 文件中,每行一个域名,例如:
# 000529.xyz
# 000577.xyz
# test
# score = score_number("996662")
input_file = '/Users/tosaki/Downloads/download (2).txt'
scored_domains = []
try:
with open(input_file, "r", encoding="utf-8") as f:
lines = f.readlines() # 读取所有行以便使用 tqdm 进度条
for line in tqdm(lines, desc="Processing domains"):
line = line.strip()
if not line:
continue # 跳过空行
# 提取6位数字部分(假定格式为 "六位数字.xyz")
parts = line.split(".")
num_str = parts[0]
if len(num_str) != 6 or not num_str.isdigit():
print(f"跳过无效格式行:{line}")
continue
# 计算得分
score = score_number(num_str)
scored_domains.append((line, score))
except FileNotFoundError:
print(f"文件 {input_file} 不存在!")
return
# 按得分倒序排序,若得分相同则按域名字符串排序
scored_domains.sort(key=lambda x: (-x[1], x[0]))
# 输出结果(这里只输出前1000个)
print("域名得分(按得分倒序):")
for domain, score in scored_domains[:500]:
print(f"{domain} -> 得分:{score}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment