Esempio n. 1
0
 def test_not_operation_with_input_not_initially_set(self):
     wireSignalMap = {}
     commands = []
     commands.append(LogicGate.parseInstruction('NOT y -> a'))
     commands.append(LogicGate.parseInstruction('101 -> y'))
     LogicGate.processCommandList(commands, wireSignalMap)
     self.assertEqual(65434, wireSignalMap['a'])
Esempio n. 2
0
 def test_set_operation_variable(self):
     wireSignalMap = {}
     commands = []
     commands.append(LogicGate.parseInstruction('x -> a'))
     commands.append(LogicGate.parseInstruction('123 -> x'))
     LogicGate.processCommandList(commands, wireSignalMap)
     self.assertEqual(123, wireSignalMap['a'])
Esempio n. 3
0
 def test_rshift_operation_with_input_set(self):
     wireSignalMap = {}
     commands = []
     commands.append(LogicGate.parseInstruction('6 -> x'))
     commands.append(LogicGate.parseInstruction('x RSHIFT 4 -> a'))
     LogicGate.processCommandList(commands, wireSignalMap)
     self.assertEqual(0, wireSignalMap['a'])
Esempio n. 4
0
 def test_or_operation_with_inputs_set(self):
     wireSignalMap = {}
     commands = []
     commands.append(LogicGate.parseInstruction('6 -> x'))
     commands.append(LogicGate.parseInstruction('13 -> y'))
     commands.append(LogicGate.parseInstruction('x OR y -> a'))
     LogicGate.processCommandList(commands, wireSignalMap)
     self.assertEqual(15, wireSignalMap['a'])
Esempio n. 5
0
 def test_and_operation_with_one_input_initially_set(self):
     wireSignalMap = {}
     commands = []
     commands.append(LogicGate.parseInstruction('6 -> x'))
     commands.append(LogicGate.parseInstruction('x AND y -> a'))
     commands.append(LogicGate.parseInstruction('13 -> y'))
     LogicGate.processCommandList(commands, wireSignalMap)
     self.assertEqual(False, 'c' in wireSignalMap)
Esempio n. 6
0
 def test_puzzle_input(self):
     wireSignalMap = {}
     commands = []
     commands.append(LogicGate.parseInstruction('123 -> x'))
     commands.append(LogicGate.parseInstruction('456 -> y'))
     commands.append(LogicGate.parseInstruction('x AND y -> d'))
     commands.append(LogicGate.parseInstruction('x OR y -> e'))
     commands.append(LogicGate.parseInstruction('x LSHIFT 2 -> f'))
     commands.append(LogicGate.parseInstruction('y RSHIFT 2 -> g'))
     commands.append(LogicGate.parseInstruction('NOT x -> h'))
     commands.append(LogicGate.parseInstruction('NOT y -> a'))
     LogicGate.processCommandList(commands, wireSignalMap)
     self.assertEqual(72, wireSignalMap['d'])
     self.assertEqual(507, wireSignalMap['e'])
     self.assertEqual(492, wireSignalMap['f'])
     self.assertEqual(114, wireSignalMap['g'])
     self.assertEqual(65412, wireSignalMap['h'])
     self.assertEqual(65079, wireSignalMap['a'])
     self.assertEqual(123, wireSignalMap['x'])
     self.assertEqual(456, wireSignalMap['y'])
Esempio n. 7
0
 def test_parse_not_operation(self):
     result = LogicGate.parseInstruction('NOT a -> x')
     self.assertEqual('NOT', result['input']['operation'])
     self.assertEqual('a', result['input']['right'])
     self.assertEqual('x', result['output'])
Esempio n. 8
0
 def test_parse_set_operation(self):
     result = LogicGate.parseInstruction('123 -> x')
     self.assertEqual('SET', result['input']['operation'])
     self.assertEqual('123', result['input']['value'])
     self.assertEqual('x', result['output'])
Esempio n. 9
0
 def test_parse_two_input_operation(self):
     result = LogicGate.parseInstruction('p LSHIFT 2 -> z')
     self.assertEqual('LSHIFT', result['input']['operation'])
     self.assertEqual('p', result['input']['left'])
     self.assertEqual(2, result['input']['right'])
     self.assertEqual('z', result['output'])
Esempio n. 10
0
# day 7 logic gates
# given input of the form:
# x AND y -> z
# where x and y are inputs that carry a 16 bit number,
# AND is one of several supported operations
# z is the output

def parseInstruction(line):
    instruction = line.split(' -> ')
    return {'input' : instruction[0], 'output': instruction[1]}

#parseInstruction("123 -> x")cd
#parseInstruction("x AND y -> z")
#parseInstruction("NOT e -> f")

from logicGate import LogicGate

commands= []
commands.append(LogicGate.parseInstruction('956 -> b'))
wireSignalMap = {}
f = open('input.txt','r')
for line in f:
    commands.append(LogicGate.parseInstruction(line.strip()))

LogicGate.processCommandList(commands, wireSignalMap)

print(wireSignalMap['a'])