예제 #1
0
 def update(self, fallback_color, now):
     if self.color is None:
         self.color = fallback_color
     color = read_line(AIBehaviour.AI_AMBIENT_FILE)
     if color != "":
         # Cache a copy of the color to prevent flickering
         # in case of file read errors
         self.color = color
     return self.color, True
예제 #2
0
    for i in range(0, len(memory), 4):
        opcode = memory[i]

        if opcode == 99:
            break

        p1 = memory[memory[i + 1]]
        p2 = memory[memory[i + 2]]
        dst = memory[i + 3]

        memory[dst] = p1 + p2 if opcode == 1 else p1 * p2

    return memory[0]


def part2(memory):
    expected = 19690720

    for noun in range(100):
        for verb in range(100):
            result = execute(list(memory), noun, verb)

            if result == expected:
                return 100 * noun + verb


program = util.read_line("input/02.txt")
memory = list(map(int, program.split(",")))
util.run(part1, part2, memory)
예제 #3
0
            if digits[i] > digits[i + 1]:
                return False

            if digits[i] == digits[i + 1]:
                valid = True

        return valid

    return sum(is_valid(num) for num in range(low, high + 1))


def part2(low, high):
    def is_valid(number):
        digits = str(number)
        count = [0] * 10
        count[int(digits[5])] = 1

        for i in range(5):
            if digits[i] > digits[i + 1]:
                return False

            count[int(digits[i])] += 1

        return 2 in count

    return sum(is_valid(num) for num in range(low, high + 1))


low, high = map(int, util.read_line("input/04.txt").split("-"))
util.run(part1, part2, low, high)
예제 #4
0
 def read_lnet_stat():
     return util.read_line(url).split()[index]
예제 #5
0
 def read_int_stat():
     return int(util.read_line(url))
예제 #6
0
 def is_healthy():
     contents = util.read_line(HEALTH_CHECK_URL)
     return int(contents == 'healthy')
예제 #7
0
    return result[1]


def part2(nums):
    width, height = 25, 6
    layers = len(data) // (width * height)

    image = [[2 for x in range(width)] for y in range(height)]

    for layer in range(layers):
        z = layer * width * height

        for y in range(height):
            for x in range(width):
                if image[y][x] == 2:
                    image[y][x] = data[z + (y * width) + x]

    result = "\n"
    for y in range(height):
        for x in range(width):
            result += "O" if image[y][x] == 1 else "."
        result += "\n"

    return result[:-1]


line = util.read_line("input/08.txt")
data = [int(px) for px in line]
util.run(part1, part2, data)