Пример #1
0
class Y2017D10(object):
    def __init__(self, file_name):
        self.input = Input(file_name).line()

    def part1(self):
        circle: List[int] = list(range(256))
        circle_size = len(circle)

        current_position = 0
        skip_size = 0

        for length in self.input.split(','):
            length = int(length)
            for i in range(length // 2):
                from_index: int = (current_position + i) % circle_size
                to_index: int = (current_position + length - i - 1) % circle_size
                temp: int = circle[from_index]
                circle[from_index] = circle[to_index]
                circle[to_index] = temp

            current_position = (current_position + length + skip_size) % circle_size
            skip_size += 1

        result = circle[0] * circle[1]
        print("Part 1:", result)

    def part2(self):
        result = KnotHash(self.input).hex

        print("Part 2:", result)
Пример #2
0
    def __init__(self, file_name):
        line = Input(file_name).line()
        codes = line.split(',')

        self._flash = {}
        for index in range(len(codes)):
            self._flash[index] = int(codes[index])

        self.ram = {}
        self.instruction_pointer = 0
        self.halted = False
        self.waiting_for_input = False
        self._input_address = 0
        self.has_output = False
        self._output_value = 0
        self._relative_base = 0

        self.reset()
Пример #3
0
    def __init__(self, file_name):
        line = Input(file_name).line()

        self.furthest_distance = 0
        self.coordinate = Coordinate(0, 0)
        for step in line.split(","):
            if step == 'n':
                self.coordinate = self.coordinate.up()
            elif step == 's':
                self.coordinate = self.coordinate.down()
            elif step == 'ne':
                self.coordinate = self.coordinate.right()
            elif step == 'sw':
                self.coordinate = self.coordinate.left()
            elif step == 'nw':
                self.coordinate = self.coordinate.left().up()
            elif step == 'se':
                self.coordinate = self.coordinate.right().down()

            self.furthest_distance = max(self.furthest_distance,
                                         self._distance(self.coordinate))
Пример #4
0
 def __init__(self, file_name):
     line = Input(file_name).line()
     self._fish: List[int] = [int(x) for x in line.split(',')]
Пример #5
0
    def __init__(self, file_name):
        line = Input(file_name).line()

        dance_moves = line.split(',')
        self.dance = ProgramDance(dance_moves)
Пример #6
0
 def __init__(self, file_name):
     line = Input(file_name).line()
     self._root = self._make_tree(iter(line.split(' ')))
Пример #7
0
 def __init__(self, file_name):
     line = Input(file_name).line()
     array = line.split('-')
     self.start = int(array[0])
     self.end = int(array[1])
Пример #8
0
 def __init__(self, file_name):
     line = Input(file_name).line()
     self.starting = [int(x) for x in line.split(',')]
Пример #9
0
    def __init__(self, file_name):
        line = Input(file_name).line()

        self.moves = line.split(', ')