|
| 1 | +import random |
| 2 | +import json |
| 3 | + |
| 4 | +white_possibles = list(range(1, 70)) |
| 5 | +red_possibles = list(range(1, 27)) |
| 6 | + |
| 7 | +tickets_per_drawing = 100 |
| 8 | +num_drawings = 15600 |
| 9 | + |
| 10 | +total_spent = 0 |
| 11 | +earnings = 0 |
| 12 | + |
| 13 | +times_won = { |
| 14 | + "5+P": 0, |
| 15 | + "5": 0, |
| 16 | + "4+P": 0, |
| 17 | + "4": 0, |
| 18 | + "3+P": 0, |
| 19 | + "3": 0, |
| 20 | + "2+P": 0, |
| 21 | + "1+P": 0, |
| 22 | + "P": 0, |
| 23 | + "0": 0, |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +def calc_win_amt(my_numbers, winning_numbers): |
| 28 | + win_amt = 0 |
| 29 | + |
| 30 | + white_matches = len(my_numbers["whites"].intersection( |
| 31 | + winning_numbers["whites"])) |
| 32 | + power_match = my_numbers["red"] == winning_numbers["red"] |
| 33 | + |
| 34 | + if white_matches == 5: |
| 35 | + if power_match: |
| 36 | + win_amt = 2_000_000_000 |
| 37 | + times_won["5+P"] += 1 |
| 38 | + else: |
| 39 | + win_amt = 1_000_000 |
| 40 | + times_won["5"] += 1 |
| 41 | + elif white_matches == 4: |
| 42 | + if power_match: |
| 43 | + win_amt = 50_000 |
| 44 | + times_won["4+P"] += 1 |
| 45 | + else: |
| 46 | + win_amt = 100 |
| 47 | + times_won["4"] += 1 |
| 48 | + elif white_matches == 3: |
| 49 | + if power_match: |
| 50 | + win_amt = 100 |
| 51 | + times_won["3+P"] += 1 |
| 52 | + else: |
| 53 | + win_amt = 7 |
| 54 | + times_won["3"] += 1 |
| 55 | + elif white_matches == 2 and power_match: |
| 56 | + win_amt = 7 |
| 57 | + times_won["2+P"] += 1 |
| 58 | + elif white_matches == 1 and power_match: |
| 59 | + win_amt = 4 |
| 60 | + times_won["1+P"] += 1 |
| 61 | + elif power_match: |
| 62 | + win_amt = 4 |
| 63 | + times_won["P"] += 1 |
| 64 | + else: |
| 65 | + times_won["0"] += 1 |
| 66 | + |
| 67 | + return win_amt |
| 68 | + |
| 69 | + |
| 70 | +# for drawing in range(num_drawings): |
| 71 | +hit_jp = False |
| 72 | +drawings = 0 |
| 73 | +years = 0 |
| 74 | +while True: |
| 75 | + drawings += 1 |
| 76 | + white_drawing = set(random.sample(white_possibles, k=5)) |
| 77 | + red_drawing = random.choice(red_possibles) |
| 78 | + |
| 79 | + winning_numbers = {"whites": white_drawing, "red": red_drawing} |
| 80 | + |
| 81 | + for ticket in range(tickets_per_drawing): |
| 82 | + total_spent += 2 |
| 83 | + my_whites = set(random.sample(white_possibles, k=5)) |
| 84 | + my_red = random.choice(red_possibles) |
| 85 | + |
| 86 | + my_numbers = {"whites": my_whites, "red": my_red} |
| 87 | + |
| 88 | + win_amt = calc_win_amt(my_numbers, winning_numbers) |
| 89 | + earnings += win_amt |
| 90 | + |
| 91 | + if win_amt == 2_000_000_000: |
| 92 | + hit_jp = True |
| 93 | + break |
| 94 | + |
| 95 | + if drawings % 156 == 0: |
| 96 | + years += 1 |
| 97 | + print(f'{years} years') |
| 98 | + |
| 99 | + if hit_jp: |
| 100 | + break |
| 101 | + |
| 102 | +print(f'Spent: ${total_spent}') |
| 103 | +print(f'Earnings: ${earnings}') |
| 104 | + |
| 105 | +print(json.dumps(times_won, indent=2)) |
0 commit comments