Minimum Time Required

  • + 0 comments

    this is my solution, it's a bit complicated but it works =).

    def minTime(machines, goal):
        sum_mach = sum(1/x for x in machines)
        days = [1, int(goal/sum_mach)]      
        n = 1
        print(days[-1])
        while True:               
            sum_prod = sum(days[-1]//x for x in machines)
            prom = ((goal-sum_prod)/2)**n;   
            min_mac = min([x - (days[-1] % x) for x in machines]) * prom
            if sum_prod >= goal:
                if prom == 1:
                    break 
                else:
                    days[-1] = days[-2]
                    n = 0                     
            else: 
                days.append(days[-1]+min_mac)            
            print(prom, sum_prod)        
        return(int(days[-1]))