Esempio n. 1
0
def test_inputs():
    """Take the data from the input file
    and display the max money by calling
    the get_max_money function and return generator"""
    # Get data from the input file and unpacking it to three variable
    get_data = read_input()
    restructuring_info = get_data[0]
    machine_info = get_data[1]
    length = get_data[2]
    # start, end to slice the generator
    start, end = 0, 0
    # Loop through lenght of restructuring
    # Get x (restructuring_info) and y (machine_info)
    # Use x, y as a parameter for get_max_money function
    for i in range(length):
        x = next(restructuring_info)
        y = []
        # Check if there a machine
        # clone the machine_info generator to slice it
        # the cliced generator represent the machine informations
        # that related to restructuring_info
        if int(x[0]):
            end += int(x[0])
            machine_info, m_backup = itertools.tee(machine_info)
            y = itertools.islice(m_backup, start, end)
            start = end

        yield ('Case ' + str(i + 1) + ": " + str(get_max_money(x, y)))
Esempio n. 2
0
 def test_case6(self):
     fun = get_max_money([0, 0, 0])
     self.assertEqual(fun, 0)
Esempio n. 3
0
from max_money import get_max_money
import itertools

with open('input.txt') as f:
    x = f.read().splitlines()
z = (i.split() for i in x if len(i.split()) == 3)
v = (i.split() for i in x if len(i.split()) != 3)
length = sum(1 for i in x if len(i.split()) == 3)

test = {}

s = 0
e = 0

for i in range(length):
    # print(x)
    x = next(z)
    y = []
    if int(x[0]):
        e += int(x[0])
        v, y_backup = itertools.tee(v)
        y = itertools.islice(y_backup, s, e)
        s = e
    print(get_max_money(x, y))
Esempio n. 4
0
 def test_case5(self):
     fun = get_max_money([2, 10, 11], [[1, 10, 4, 3], [1, 10, 9, 3]])
     self.assertEqual(fun, 33)
Esempio n. 5
0
 def test_case4(self):
     fun = get_max_money([1, 10, 2], [[1, 10, 2, 1]])
     self.assertEqual(fun, 10)
Esempio n. 6
0
 def test_case3(self):
     fun = get_max_money([1, 12, 30], [[30, 10, 5, 3]])
     self.assertEqual(fun, 12)
Esempio n. 7
0
 def test_case2(self):
     fun = get_max_money([0, 11, 30])
     self.assertEqual(fun, 11)
Esempio n. 8
0
 def test_case1(self):
     fun = get_max_money([6, 10, 20],
                         [[6, 12, 1, 3], [1, 9, 1, 2], [3, 2, 1, 2],
                          [8, 20, 5, 4], [4, 11, 7, 4], [2, 10, 9, 1]])
     self.assertEqual(fun, 44)