Python用プログラミング
- Google colaboratory
- JUNO
copilotやgeminiに次のページのプログラミングをコピペして質問し、あなた好みにする。エラーが出たらその内容をコピペして訂正していく。AIに頼めば書いてくれる。
予想
import random
class RaceHorse:
def __init__(self, name, dosage_index, center_of_distribution, speed_index, family_number_score, corner_position=None, finish_position=None, popularity=None, horse_number=None):
self.name = name
self.dosage_index = dosage_index
self.center_of_distribution = center_of_distribution
self.speed_index = speed_index
self.family_number_score = family_number_score
self.corner_position = corner_position
self.finish_position = finish_position
self.popularity = popularity
self.horse_number = horse_number
def calculate_score(self):
dosage_weight = 0.25
center_weight = 0.2
speed_weight = 0.35
family_weight = 0.2
base_score = (
self.dosage_index * dosage_weight +
self.center_of_distribution * center_weight +
self.speed_index * speed_weight +
self.family_number_score * family_weight
)
if self.corner_position is not None and self.finish_position is not None:
position_change = self.corner_position - self.finish_position
position_weight = 0.1
base_score += position_change * position_weight
if self.popularity is not None:
popularity_weight = 0.15
base_score += (1 / self.popularity) * popularity_weight
return base_score
def process_horse_data(horses):
for horse in horses:
if horse.corner_position is not None and horse.finish_position is not None:
change = horse.corner_position - horse.finish_position
print(f"{horse.name}: 4コーナー位置から{change}順位の変化 (着順: {horse.finish_position})")
else:
print(f"{horse.name}: 過去のコーナー位置と着順のデータがありません。")
def predict_winner(horses):
best_horse = None
highest_score = 0
for horse in horses:
score = horse.calculate_score()
print(f"{horse.name} のスコア: {score:.2f}")
if score > highest_score:
highest_score = score
best_horse = horse
return best_horse
def suggest_win5_bets(races, max_rank=12, max_selection=5):
recommended_bets = []
for race in races:
race_horses = sorted(race, key=lambda horse: horse.calculate_score(), reverse=True)
recommended_for_race = [horse.name for horse in race_horses if horse.popularity is not None and horse.popularity <= max_rank][:max_selection]
if len(recommended_for_race) < max_selection:
remaining_horses = [horse.name for horse in race_horses if horse.name not in recommended_for_race]
recommended_for_race.extend(remaining_horses[:max_selection - len(recommended_for_race)])
recommended_bets.append(recommended_for_race)
return recommended_bets
def generate_combinations(race, num_combinations=100):
num_horses = len(race)
top_favorites = sorted(race, key=lambda horse: horse.calculate_score(), reverse=True)[:2]
mid_favorites = sorted(race, key=lambda horse: horse.calculate_score(), reverse=True)[2:4]
low_favorites = sorted(race, key=lambda horse: horse.calculate_score())[:8]
top_favorites_numbers = [horse.horse_number for horse in top_favorites]
mid_favorites_numbers = [horse.horse_number for horse in mid_favorites]
low_favorites_numbers = [horse.horse_number for horse in low_favorites]
combinations = []
for _ in range(num_combinations):
combination = []
combination.append(random.choice(top_favorites_numbers + low_favorites_numbers))
combination.append(random.choice(top_favorites_numbers + low_favorites_numbers))
combination.append(random.choice(mid_favorites_numbers))
if (sum(1 for x in combination if x % 2 == 0) == 1 or sum(1 for x in combination if x % 2 == 0) == 2) and \
(sum(1 for x in combination if x <= num_horses // 2) == 1 or sum(1 for x in combination if x <= num_horses // 2) == 2):
combinations.append(combination)
return combinations
horses_race1 = [
RaceHorse("Horse A", 2.0, 0.5, 90, 8, 8, 2, 1, 1),
RaceHorse("Horse B", 1.8, 0.3, 85, 9, 6, 3, 2, 2),
RaceHorse("Horse C", 1.5, -0.2, 88, 7, 5, 4, 3, 3),
RaceHorse("Horse D", 1.5, -0.2, 88, 7, 3, 1, 5, 4),
RaceHorse("Horse E", 1.5, -0.2, 88, 7, 1, 5, 8, 5),
RaceHorse("Horse F", 1.5, -0.2, 88, 7, 2, 2, 12, 6),
RaceHorse("Horse G", 1.5, -0.2, 88, 7, 4, 6, 4, 7),
RaceHorse("Horse H", 1.5, -0.2, 88, 7, 7, 7, 7, 8)
]
horses_race2 = [
RaceHorse("Horse I", 2.0, 0.5, 90, 8, 8, 2, 2, 1),
RaceHorse("Horse J", 1.8, 0.3, 85, 9, 6, 3, 1, 2),
RaceHorse("Horse K", 1.5, -0.2, 88, 7, 5, 4, 5, 3),
RaceHorse("Horse L", 1.5, -0.2, 88, 7, 3, 1, 3, 4),
RaceHorse("Horse M", 1.5, -0.2, 88, 7, 1, 5, 4, 5),
RaceHorse("Horse N", 1.5, -0.2, 88, 7, 2, 2, 6, 6),
RaceHorse("Horse O", 1.5, -0.2, 88, 7, 4, 6, 12, 7),
RaceHorse("Horse P", 1.5, -0.2, 88, 7, 7, 7, 8, 8)
]
races = [horses_race1, horses_race2]
process_horse_data(horses_race1)
winner_race1 = predict_winner(horses_race1)
print(f"勝ちそうな馬は: {winner_race1.name}")
suggested_bets = suggest_win5_bets(races)
for i, race_bets in enumerate(suggested_bets):
print(f"Recommended bets for Race {i+1}: {race_bets}")
combinations_race1 = generate_combinations(horses_race1)
for combo in combinations_race1:
print(combo)
展開と着順
def process_horse_data(horse_data):
"""
複数の馬の4コーナー位置と着順のデータを処理し、結果を出力します。
Parameters:
horse_data (dict): 各馬のデータを辞書形式で格納したデータ構造
例: {
"馬1": [
{"corner": 8, "finish": 2}, # 前走コーナー、フィニッシュ
{"corner": 6, "finish": 3} # 前々走コーナー、フィニッシュ
],
"馬2": [
{"corner": 5, "finish": 4}, # 前走コーナー、フィニッシュ
{"corner": 2, "finish": 3} # 前々走コーナー、フィニッシュ
]
}
"""
for horse_name, races in horse_data.items():
print(f"【{horse_name}】")
for i, race in enumerate(races):
corner = race["corner"]
finish = race["finish"]
change = corner - finish
print(f"{'前走' if i == 0 else '前々走'}: 4コーナー位置から{change}順位の変化 (着順: {finish})") #着順を追記
print("-" * 20) # 馬ごとの区切り
# テストデータ(辞書形式で複数の馬のデータを格納)
horse_data = {
"馬1": [
{"corner": 4コーナー数字入力, "finish": 着順数字入力}, # 前走コーナー、フィニッシュ
{"corner": 4コーナー数字入力, "finish": 着順数字入力} # 前々走コーナー、フィニッシュ
],
"馬2": [
{"corner": 4コーナー数字入力, "finish": 着順数字入力}, # 前走コーナー、フィニッシュ
{"corner": 4コーナー数字入力, "finish": 着順数字入力} # 前々走コーナー、フィニッシュ
]
}
# データを処理
process_horse_data(horse_data)
WIN5
def suggest_win5_bets(horse_numbers, popularity_numbers, max_rank=12, max_horses=18, max_selection=5):
"""
A function to suggest WIN5 bets, ensuring exactly 'max_selection' horses are selected per race.
:param horse_numbers: Horse numbers for each race (list of lists)
:param popularity_numbers: Popularity rankings for each race (list of lists)
:param max_rank: Maximum rank to include in recommendations (default: 12)
:param max_horses: Maximum number of horses allowed per race (default: 18)
:param max_selection: Exactly how many horses to select per race (default: 5)
:return: A list of recommended bets
"""
# Validate input data
if len(horse_numbers) != 5 or len(popularity_numbers) != 5:
raise ValueError("WIN5 requires data for exactly 5 races. Ensure both horse_numbers and popularity_numbers have 5 entries.")
for i in range(5):
if len(horse_numbers[i]) > max_horses or len(popularity_numbers[i]) > max_horses:
raise ValueError(f"Race {i+1} exceeds the maximum allowed number of horses ({max_horses}). Check the input data.")
recommended_bets = []
# Apply conditions for each race
for i in range(5):
race_horse_numbers = horse_numbers[i]
race_popularity = popularity_numbers[i]
# Select horse numbers ranked within the specified max_rank
recommended_for_race = [
(horse, pop) for horse, pop in zip(race_horse_numbers, race_popularity) if 1 <= pop <= max_rank
]
# Sort by popularity to prioritize top-ranked horses
recommended_for_race = sorted(recommended_for_race, key=lambda x: x[1])
# If fewer than max_selection horses meet the criteria, add remaining horses in order
if len(recommended_for_race) < max_selection:
remaining_horses = [
(horse, None) for horse in race_horse_numbers if horse not in [h for h, _ in recommended_for_race]
]
recommended_for_race.extend(remaining_horses)
# Limit to exactly max_selection horses
recommended_for_race = recommended_for_race[:max_selection]
# Extract only horse numbers from the final list
recommended_for_race = [horse for horse, _ in recommended_for_race]
recommended_bets.append(recommended_for_race)
return recommended_bets
# Example Input Data
horse_numbers = [
[1, 3, 5, 7, 9], # Horse numbers for Race 1
[2, 4, 6, 8, 10], # Horse numbers for Race 2
[11, 13, 15, 17, 18], # Horse numbers for Race 3
[1, 2, 3, 4, 5], # Horse numbers for Race 4
[8, 10, 12, 14, 16] # Horse numbers for Race 5
]
popularity_numbers = [
[2, 1, 13, 10, 12], # Popularity rankings for Race 1
[3, 5, 6, 15, 9], # Popularity rankings for Race 2
[1, 4, 10, 12, 15], # Popularity rankings for Race 3
[5, 16, 2, 1, 3], # Popularity rankings for Race 4
[3, 8, 5, 20, 7] # Popularity rankings for Race 5
]
# Generate Recommended Bets
suggested_bets = suggest_win5_bets(horse_numbers, popularity_numbers)
# Display Results
for i, race_bets in enumerate(suggested_bets):
print(f"Recommended bets for Race {i+1}: {race_bets}")
予想用
# 馬のデータを表すクラス
class RaceHorse:
def __init__(self, name, dosage_index, center_of_distribution, speed_index, family_number_score):
self.name = name
self.dosage_index = dosage_index
self.center_of_distribution = center_of_distribution
self.speed_index = speed_index
self.family_number_score = family_number_score
# 馬の総合スコアを計算する
def calculate_score(self):
# 重み付けの比率を設定
dosage_weight = 0.25
center_weight = 0.2
speed_weight = 0.35
family_weight = 0.2
# スコア計算
return (
self.dosage_index * dosage_weight +
self.center_of_distribution * center_weight +
self.speed_index * speed_weight +
self.family_number_score * family_weight
)
# 馬データの作成
horses = [
RaceHorse("Horse A", dosage_index=2.0, center_of_distribution=0.5, speed_index=90, family_number_score=8),
RaceHorse("Horse B", dosage_index=1.8, center_of_distribution=0.3, speed_index=85, family_number_score=9),
RaceHorse("Horse C", dosage_index=1.5, center_of_distribution=-0.2, speed_index=88, family_number_score=7),
]
# 勝ちそうな馬を選ぶ
def predict_winner(horses):
best_horse = None
highest_score = 0
for horse in horses:
score = horse.calculate_score()
print(f"{horse.name} のスコア: {score:.2f}")
if score > highest_score:
highest_score = score
best_horse = horse
return best_horse
# 勝ちそうな馬の表示
winner = predict_winner(horses)
print(f"勝ちそうな馬は: {winner.name}")
3連単
import random
def generate_combinations(races):
combinations = []
for race in races:
num_horses = race['num_horses']
top_favorites = race['top_favorites']
mid_favorites = race['mid_favorites']
low_favorites = race['low_favorites']
# Generate combinations based on the given conditions
for _ in range(100): # Generate 100 combinations for each race
combination = []
# 1着
combination.append(random.choice(top_favorites + low_favorites))
# 2着
combination.append(random.choice(top_favorites + low_favorites))
# 3着
combination.append(random.choice(mid_favorites))
# Ensure the combination meets the odd/even and large/small conditions
if (sum(1 for x in combination if x % 2 == 0) == 1 or sum(1 for x in combination if x % 2 == 0) == 2) and \
(sum(1 for x in combination if x <= num_horses // 2) == 1 or sum(1 for x in combination if x <= num_horses // 2) == 2):
combinations.append(combination)
return combinations
# Example input
races = [
{
'num_horses': ここに馬番を入力する,
'top_favorites': [馬番を入力, 馬番を入力],
'mid_favorites': [馬番入力, 馬番入力],
'low_favorites': [馬番, 馬番, 馬番, 馬番, 馬番, 馬番, 馬番, 馬番]
},
# Add more races as needed
]
combinations = generate_combinations(races)
for combo in combinations:
print(combo)
コメント