Пример #1
0
def get_combinations(amount):
    data = common.get_lines(__file__)
    number = 0

    for item in combinations(data, amount):
        if sum(item) == SUM_TOTAL:
            number = reduce(lambda x, y: x * y, item)
            break

    return number
Пример #2
0
 def get_stats_files(self, list_files):
     start = time.time()
     logger.info("Generating stats files: " + PIS_EVIDENCES_STATS_FILE)
     if os.path.exists(PIS_EVIDENCES_STATS_FILE): os.remove(PIS_EVIDENCES_STATS_FILE)
     stats_file = open(PIS_EVIDENCES_STATS_FILE, "a+")
     for original_filename in list_files:
         lines = get_lines(original_filename)
         filename_info = original_filename.rsplit('/', 1)[1]
         stats_file.write(filename_info + ',' + str(lines) + '\n')
     end=time.time()
     logging.info("Stats evidence file: time of execution {}".format(str(end - start)))
Пример #3
0
            new_coordinates = {}
            coordinates = set()

            for item in self.coordinates:
                neighbours = self.get_neighbours(item, is_hypercube)
                coordinates.add(item)
                coordinates = coordinates.union(neighbours)

            for item in coordinates:
                state = self.get_state(item)
                neighbours = self.get_neighbours(item, is_hypercube)
                total = self.get_states(neighbours).count(ACTIVE)

                if state == ACTIVE and (total != 2 and total != 3):
                    new_coordinates[item] = INACTIVE
                elif state == INACTIVE and total == 3:
                    new_coordinates[item] = ACTIVE
                else:
                    new_coordinates[item] = state

            self.coordinates = new_coordinates

        return list(self.coordinates.values()).count(ACTIVE)


data = common.get_lines(__file__)
dimension = Dimension.from_data(data)

print('Part 1: {}'.format(dimension.run()))
print('Part 2: {}'.format(dimension.run(is_hypercube=True)))
Пример #4
0
import common


class Group(object):
    def __init__(self, people):
        self.people = people

    @classmethod
    def from_data(cls, data):
        people = []

        for item in data:
            people.append([set(item) for item in item.split('\n')])

        return cls(people)

    def get_total(self, method):
        count = 0

        for item in self.people:
            count += len(method(*item))

        return count


data = common.get_lines(__file__, split='\n\n')
groups = Group.from_data(data)

print('Part 1: {}'.format(groups.get_total(method=set.union)))
print('Part 2: {}'.format(groups.get_total(method=set.intersection)))
Пример #5
0
    def load_gold_data_TXT(self, path, train=True):
        data = common.get_lines(path)

        return data