Find if a ticket covers a date

Copper Contributor

I have a dataset more or less like this

dateExpire inAmountUseis Covered by date and Amount
01/0535  
02/05  1Yes

04/05

    
05/05   1Yes
06/05  1No
08/05  1No
09/0531  
10/05  1Yes
11/05    
12/05  1No
     
     

 

every row has a date and I need to check if for a specific date where the ticket is used the amount of ticket bought on a previous date is covered or not (based both on quantity and expire days)

 

Can someone help me with this tricky problem?

 

in python it would be something like this:

 

 

matrix = [
    [3,5,0],
    [0,0,1],
    [0,0,0],
    [0,0,1],
    [0,0,1],
    [0,0,1],
    [3,1,0],
    [0,0,1],
    [0,0,1],
]

def consume_ticket(index, tickets):
    for k_index, v_exp_amount in tickets.items():
        if v_exp_amount["expire"] < index-k_index:
            continue

        if v_exp_amount["amount"] > 0:
            v_exp_amount["amount"] -= 1
            return True
        else:
            continue
    return False

packs = {}
for index, line in enumerate(matrix):
    is_covered = False
    if line[0]:
        packs[index]={"expire":line[0],"amount":line[1]}
    if line[2]:
        is_covered = consume_ticket(index, packs)
        print(f'{index} {line} {is_covered}')
    else:
        print(f'{index} {line}')

 

0 [3, 5, 0]
1 [0, 0, 1] True
2 [0, 0, 0]
3 [0, 0, 1] True
4 [0, 0, 1] False
5 [0, 0, 1] False
6 [3, 1, 0]
7 [0, 0, 1] True
8 [0, 0, 1] False

 

 

 

 

0 Replies