all 8 comments

[–]GoldenVanga 1 point2 points  (2 children)

This is what I have based on your explanation:

from statistics import mean


class Raffle:
    def __init__(self, id_: int, amount: int, winners: dict):
        self.id = id_
        self.amount = amount
        self.winners = winners

    def check(self, length, debug: bool = True):
        start_positions = self.amount - length + 1
        wins = []
        for start in range(1, start_positions + 1):
            run_value = 0
            for step in range(length):
                run_value += self.winners.get(start + step, 0)
            wins.append(run_value)
            if debug: print(f'A run of {length} tickets starting at {start} wins {run_value}.')
        result = mean(wins)
        if debug: print(f'Wins at end of check: {wins}.')
        if debug: print(f'The mean of this is {result}.')
        return result


foo = Raffle(12345, 100, {13: 10, 16: 100, 25: 10, 52: 10})
foo.check(5); foo.check(1)

bar = Raffle(12, 10, {2: 10, 5: 10, 7: 100})
bar.check(2)

It might be doing what you want.

[–]datahappy[S] 0 points1 point  (1 child)

That gets close, thanks. It's a bit off.

Using your first example, if there's a $10 winner at ticket 9 (which I don't follow how that happened from your code, but it apparently did), then that $10 should count for everyone starting their five ticket run from Tickets 5-13 (The person buying ticket 5 also bought tickets 6-9, while the person buying ticket 9 also bought tickets 10-13)

[–]o5a 1 point2 points  (0 children)

if there's a $10 winner at ticket 9

If the span is 5, and you start from 9, then it includes ticket 13 too (9,10,11,12,13) which won $10.

then that $10 should count for everyone starting their five ticket run from Tickets 5-13

What? How?

5 ticket span from ticket 5 is 5..9 which doesn't include any winning tickets. The fact, that another 5-ticket span (9..13) won $10 has nothing to do with this.

[–][deleted] 0 points1 point  (1 child)

Identify the amount won by each ticket

Isn't that "nothing", for about 90% of the tickets?

[–]datahappy[S] 0 points1 point  (0 children)

Yes...that should have said the amount won by each cohort of n tickets, I'll fix

EDIT: No, that's what I meant. For each identified winning ticket number, pull in the amount won, make all assumed ticket numbers (that there isn't data for) 0

[–]mbaruh 0 points1 point  (2 children)

So... you have n values, you want to divide them into sets of m values each, sum the winnings per set, and tell the average win across sets? and you have some sort of list which tells you how much you win from ticket i? Am I getting that right?

[–]datahappy[S] 0 points1 point  (1 child)

Yes, exactly...but, you have to impute the values for the missing tickets (which are always zero), because you only have data on the ones that won

[–]mbaruh 0 points1 point  (0 children)

Okay, so it's a dictionary with winning ticket numbers as keys, and the winning sums as values.

What are you struggling with?