Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- # Read in the data from the text file
- with open('lottery_data.txt', 'r') as f:
- data = f.read().splitlines()
- # Convert the data to a list of winning combinations
- winning_combinations = []
- for line in data:
- winning_combinations.append(list(map(int, line.split())))
- # Create a list of all possible combinations
- all_combinations = list(itertools.product(range(1, 51), repeat=5))
- # Calculate the frequency of each number appearing in the winning combinations
- #number_frequencies = {}
- number_frequencies = {n: 0 for n in range(1, 51)}
- for combination in winning_combinations:
- for number in combination:
- if number not in number_frequencies:
- number_frequencies[number] = 1
- else:
- number_frequencies[number] += 1
- # Calculate the score for each combination based on the frequency of its numbers
- combination_scores = {}
- for combination in all_combinations:
- score = sum([number_frequencies[number] for number in combination])
- combination_scores[combination] = score
- # Sort the combinations by score and output the top 5
- top_combinations = sorted(combination_scores, key=combination_scores.get, reverse=True)[:5]
- print("The best 5 combinations are:")
- for combination in top_combinations:
- print(combination)
Advertisement
Add Comment
Please, Sign In to add comment