def test_translate(self): scotty = Scotty() res = scotty.translate('1,0,0,3,99') self.assertEqual(res, [1, 0, 0, 3, 99])
import random from enterprise import MontgomeryScott as Scotty scotty = Scotty() def part_one(): with open('input.txt', "r") as commands: trans = scotty.translate(commands.read()) res = scotty.execute(trans) print('Part one, Scotty says: {0}'.format(res[0])) def part_two(): with open('input.txt', "r") as commands: orig = scotty.translate(commands.read()) res = 0 while res != 19690720: noun = random.randint(0, 99) verb = random.randint(0, 99) program = orig.copy() program[1] = noun program[2] = verb res = scotty.execute(program)[0] print('Part two, Scotty says: {0}'.format(100 * noun + verb)) part_one() part_two()
def test_execute_four(self): scotty = Scotty() trans = scotty.translate('2,4,4,5,99,0') res = scotty.execute(trans) self.assertEqual(res, [2, 4, 4, 5, 99, 9801])
def test_execute_five(self): scotty = Scotty() trans = scotty.translate('1,1,1,4,99,5,6,0,99') res = scotty.execute(trans) self.assertEqual(res, [30, 1, 1, 4, 2, 5, 6, 0, 99])
def test_execute_two(self): scotty = Scotty() trans = scotty.translate('1,9,10,3,2,3,11,0,99,30,40,50') res = scotty.execute(trans) self.assertEqual(res, [3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50])
def test_execute_three(self): scotty = Scotty() trans = scotty.translate('2,3,0,3,99') res = scotty.execute(trans) self.assertEqual(res, [2, 3, 0, 6, 99])
import random import os from enterprise import MontgomeryScott as Scotty cwd = os.getcwd() ifile = cwd + "/input.txt" with open(ifile, "r") as commands: #Part one scotty = Scotty(input=1) trans = scotty.translate(commands.read()) res = scotty.execute(trans.copy()) print("Scotty says the solution for part one is: {0}".format(res[-1])) #Part two scotty = Scotty(input=5) res = scotty.execute(trans.copy()) print("Scotty says the solution for part two is: {0}".format(res[-1]))
def test_execute_one(self): scotty = Scotty() trans = scotty.translate('1,0,0,3,99') res = scotty.execute(trans) self.assertEqual(res, [1, 0, 0, 2, 99])
def test_translate(self): scotty = Scotty(input=1) res = scotty.translate('3,0,4,0,99') self.assertEqual(res, [3, 0, 4, 0, 99])
def test_execute_im_more_than_eight(self): scotty = Scotty(input=9) trans = scotty.translate('3,3,1107,-1,8,3,4,3,99') res = scotty.execute(trans) self.assertEqual(res, [0])
def test_execute_im_not_equal_eight(self): scotty = Scotty(input=1) trans = scotty.translate('3,3,1108,-1,8,3,4,3,99') res = scotty.execute(trans) self.assertEqual(res, [0])
def test_execute_pos_more_than_eight(self): scotty = Scotty(input=9) trans = scotty.translate('3,9,7,9,10,9,4,9,99,-1,8') res = scotty.execute(trans) self.assertEqual(res, [0])
def test_execute_pos_not_equal_eight(self): scotty = Scotty(input=1) trans = scotty.translate('3,9,8,9,10,9,4,9,99,-1,8') res = scotty.execute(trans) self.assertEqual(res, [0])