summaryrefslogtreecommitdiff
path: root/Solution/solution_debut_vente.py
blob: fc838aa3e3678a0ca52a7febf327fc47c6d86718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python3

import itertools
import pprint
import numpy


def foo(aaa):
    return aaa

file = open("../input.txt", "r")

story_table = []
stories_table = []
nb_machines = 0
loop_number = 0

for line in file:

    line_table = list(map(int, line.split()))
    keys_line_table_story = ['machines', 'money', 'time']
    keys_line_table_machines = ['day_sell', 'buy_price', 'resale_price', 'day_profit']
    l = list()
    for a in range(0, len(line_table)):
        l.append((line_table[a]))
    if len(line_table) == 3:
        line_table = dict(zip(keys_line_table_story,l))
    else:
        line_table = dict(zip(keys_line_table_machines,l))

    if len(line_table) == 3:
        nb_machines = line_table["machines"]
        if loop_number > 0:
            stories_table.append(story_table)
        story_table = []

    story_table.append(line_table)

    loop_number += 1

case = 1
for story in stories_table:
    settings = story[0]

    list_machine_number = []
    for machine_number in range(1, settings['machines']+1):
        list_machine_number.append(machine_number)

    list_all_combinations = []
    for machine_number in range(1, settings['machines']+1):
        list_all_combinations.append([list(x) for x in itertools.combinations(list_machine_number, machine_number)])

    for combination_number in range(0, len(list_all_combinations)):
        list_all_combinations[combination_number].append([])

    # Transform the two dimensionnal array in list_machine_number in one
    # dimensional array
    list_all_combinations =  [x for sublist in list_all_combinations for x in sublist]

    tests_vente_robot = []
    num_machine=0
    for machine in story:
        if len(machine) > 3:
            test_vente_robot = []
            for day in range(machine['day_sell']+1, settings['time']+1):
                test_vente_robot.append((num_machine, day))
            tests_vente_robot.append(test_vente_robot)
            num_machine+=1

    bigger_money = 0;
    for combination in list_all_combinations:

        machine_to_sell = []
        for n in combination:
            machine_to_sell.append(story[n])

        if len(combination) > 0:
            test_vente_posibilities = []
            for num in combination:
                test_vente_posibilities += tests_vente_robot[num-1]

            combination_of_robots = []
            for i in range(2, len(combination)+1):
                combination_of_robots += itertools.combinations(combination, i)

            for entry in combination_of_robots:
                str_test_vente_posibilities = ''
                for num_robot in entry:
                    if str_test_vente_posibilities != "":
                        str_test_vente_posibilities += ','
                    str_test_vente_posibilities += str(tests_vente_robot[num_robot-1])
                exec("test_vente_posibilities += itertools.product("+str_test_vente_posibilities+")")

        for possiblity in test_vente_posibilities:
            current_money = settings["money"]
            machines_bought = []
            for day in range(0, settings["time"]+1):
                for machines in machines_bought:
                    current_money += machines["day_profit"]
                buyable_machines = []
                for machine_number in range(0, len(machine_to_sell)):
                    if day == machine_to_sell[machine_number]["day_sell"]:
                        buyable_machines.append(machine_to_sell[machine_number])
                for machines in buyable_machines:
                    if machines["buy_price"] <= current_money:
                        machines_bought.append(machines)
                        current_money -= machines["buy_price"]
            if current_money > bigger_money:
                bigger_money = current_money

    if len(list_all_combinations ) == 0:
        bigger_money = settings['money']

    print("Case "+ str(case) + ": " + str(bigger_money))
    case += 1