Exemplo n.º 1
0
def main():
    initial_memory = [int(v) for v in sys.stdin.readline().split(",")]
    for noun, verb in itertools.product(range(100), repeat=2):
        tested_memory = mutate(list(initial_memory), noun, verb)
        result = execute(tested_memory)
        if result == 19690720:
            print(noun, verb, 100 * noun + verb)
            return
Exemplo n.º 2
0
def fix_mutation(operations, verbose=False):
  test_set = set()
  for i,o in enumerate(operations):
    if o[0] == 'jmp' or o[0] == 'nop':
      test_set.add(i)
  while(True):
    cache = deepcopy(operations)
    if len(test_set) == 0:
      break
    idx = test_set.pop()
    if cache[idx][0] == 'nop':
      cache[idx][0] = 'jmp'
    elif cache[idx][0] == 'jmp':
      cache[idx][0] = 'nop'
    acc, valid = execute(cache)
    if valid:
      return acc
Exemplo n.º 3
0
    def test_global(self):
        TestCase = namedtuple("TestCase", ["wire_1", "wire_2", "result"])
        test_cases = [
            TestCase(
                ["R8", "U5", "L5", "D3"],
                ["U7", "R6", "D4", "L4"],
                6,
            ),
            TestCase(
                ["R75", "D30", "R83", "U83", "L12", "D49", "R71", "U7", "L72"],
                ["U62", "R66", "U55", "R34", "D71", "R55", "D58", "R83"],
                159,
            ),
            TestCase(
                [
                    "R98",
                    "U47",
                    "R26",
                    "D63",
                    "R33",
                    "U87",
                    "L62",
                    "D20",
                    "R33",
                    "U53",
                    "R51",
                ],
                [
                    "U98", "R91", "D20", "R16", "D67", "R40", "U7", "R15",
                    "U6", "R7"
                ],
                135,
            ),
        ]

        for test_case in test_cases:
            with self.subTest():
                result = execute(test_case.wire_1, test_case.wire_2)
                self.assertEqual(test_case.result, result)
Exemplo n.º 4
0
Arquivo: main.py Projeto: krutt/ML
# ML HW2 Q2
# Author: Andrew Nedea
import common
import part1
import part2

d20_train = common.generate_data(20)
d200_train = common.generate_data(200)
d2000_train = common.generate_data(2000)
d10000_validate = common.generate_data(10000)

part1.execute(d10000_validate)
part2.execute(d20_train, d200_train, d2000_train, d10000_validate)

Exemplo n.º 5
0
"""
Advent of code 2016 - Day 12, Part 2

Leonardo's Monorail
===
As you head down the fire escape to the monorail, you notice it didn't start;
register c needs to be initialized to the position of the ignition key.

If you instead initialize register c to be 1, what value is now left in
register a?
"""
import fileinput
from part1 import execute, Computer

if __name__ == '__main__':
    computer = Computer()
    computer.registers['c'] = 1
    execute([x.strip().lower() for x in fileinput.input()], computer)