예제 #1
0
def main():
    gen = inputgetter.get_input(gen=True)

    for line in gen:
        gate = Gate(line.strip())
        Gate.gates[gate.name] = gate

    a_val = Gate.get_val('a')
    print("Value of a is: {}".format(a_val))

    for key in Gate.gates:
        Gate.gates[key].value = None

    Gate.gates['b'].value = a_val

    print("Value of a after rewiring b is: {}".format(Gate.get_val('a')))
예제 #2
0
def main():
    total = 0
    total_mem = 0
    content = inputgetter.get_input(gen=True)

    for line in content:
        line = line.strip()
        total += len(line)

        in_escape = False
        in_hex = False
        for char in line:
            if char == '"':





    print(total)
예제 #3
0
	current_char = string[0]
	for char in string[1:]:
		if char == current_char:
			return True
		else:
			current_char = char

def has_pairs(string):
	for x in range(len(string) - 1):
		if string.count(string[x:x+2], x + 2) >= 1:
			return True
	return False

def has_burger_pairs(string):
	return re.search(r"(\w)\w\1", string) is not None

if __name__ == '__main__':
	content = inputgetter.get_input().split("\n")
	count = 0
	count2 = 0
	
	for string in content:
		if is_nice(string):
			count += 1
		if is_nice2(string):
			count2 += 1

	print("There are {} nice words".format(count))
	print("There are {} nice words".format(count2))

예제 #4
0
            if i % 2 == 0:
                self.x, self.y = self._move(instruct, self.x, self.y)
            else:
                self.rx, self.ry = self._move(instruct, self.rx, self.ry)

        return self.houses_delivered

    def _move(self, instruction, x, y):
        if instruction == "^":
            y += 1
        elif instruction == "<":
            x -= 1
        elif instruction == "v":
            y -= 1
        elif instruction == ">":
            x += 1

        if (x, y) not in self.visited:
            self.houses_delivered += 1
            self.visited.add((x, y))

        return x, y


if __name__ == "__main__":
    directions = inputgetter.get_input()
    result = Santa().deliver_presents(directions)
    with_robo = Santa().deliver_presents_with_robot(directions)
    print("# Houses receiving presents: {}".format(result))
    print("# Houses receiving presents with robo: {}".format(with_robo))
예제 #5
0
			raise Exception('Instruction parse error for: ' + inst)

		if match_groups.group(1) == 'turn off':
			inst_type = InstructionType.off
		elif match_groups.group(1) == 'turn on':
			inst_type = InstructionType.on
		else:
			inst_type = InstructionType.toggle

		yield Instruction(inst_type,
				int(match_groups.group(2)),
				int(match_groups.group(3)),
				int(match_groups.group(4)),
				int(match_groups.group(5)))


if __name__ == '__main__':
	gen = inputgetter.get_input(gen=True)

	grid = [[False] * 1000 for _ in range(1000)]
	grid2 = [[0] * 1000 for _ in range(1000)]

	for inst in get_next_instruction(gen):
		inst.perform_inst(grid, grid2)

	count = sum(sum(row) for row in grid)
	count2 = sum(sum(row) for row in grid2)

	print("Number of lights lit: {}".format(count))
	print("Total Brightness: {}".format(count2))
예제 #6
0
import inputgetter
import functools

def solve(content):
    step = lambda acc, curr: acc + (1 if curr == '(' else -1)
    return functools.reduce(step, content, 0)

def solve2(content):
    floor = 0
    for i, instruction in enumerate(content):
        floor += (1 if instruction == '(' else -1)
        if floor == -1:
            return i + 1

if __name__ == '__main__':
    content = inputgetter.get_input()
    print("Floor #: {}".format(solve(content)))
    print("First reached basement at instruction #: {}".format(solve2(content)))