def test1(self): data = '''10 ORE => 10 A 1 ORE => 1 B 7 A, 1 B => 1 C 7 A, 1 C => 1 D 7 A, 1 D => 1 E 7 A, 1 E => 1 FUEL'''.splitlines() reactions = parse(data) expected = 31 self.assertEqual(react(reactions), expected)
def test2(self): data = '''9 ORE => 2 A 8 ORE => 3 B 7 ORE => 5 C 3 A, 4 B => 1 AB 5 B, 7 C => 1 BC 4 C, 1 A => 1 CA 2 AB, 3 BC, 4 CA => 1 FUEL'''.splitlines() reactions = parse(data) expected = 165 self.assertEqual(react(reactions), expected)
def react(self, reactants): return reaction.react(reactants)
def test13312(self): reactions = parse(data_13312) self.assertEqual(react(reactions), 13312) # PartII self.assertEqual(react(reactions, 82892753), 999999999076) self.assertEqual(react(reactions, 82892754), 1000000011012)
def test2210736(self): reactions = parse(data_2210736) self.assertEqual(react(reactions), 2210736) # PartII self.assertEqual(react(reactions, 460664), 999998346916) self.assertEqual(react(reactions, 460665), 1000000542454)
def test180697(self): reactions = parse(data_180697) self.assertEqual(react(reactions), 180697) # PartII self.assertEqual(react(reactions, 5586022), 999999895124) self.assertEqual(react(reactions, 5586023), 1000000073532)
import os from kinetic_accelerometer import kinetic_accelerometer from static_accelerometer import static_accelerometer from static_segmentation import static_segment from kinetic_segmentation import kinetic_segment from reaction import react from prune_data import prune_data #all methods have three parameters(date,fov,filename) date = "06-12" for f in os.listdir(date + "/Ganglion"): if f.endswith(".txt") and f.startswith("k"): kinetic_segment(date, int(f[2:4]), f) kinetic_accelerometer(date, int(f[2:4]), f) if f.endswith(".txt") and f.startswith("s"): static_segment(date, int(f[2:4]), f) static_accelerometer(date, int(f[2:4]), f) react(date, int(f[2:4]), f) prune_data(date, int(f[2:4]), f)
#!/usr/bin/env python3 from parser import parse from reaction import react from reaction import findMaximumYield if __name__ == '__main__': with open('input', 'r') as f: reactions = parse(f.readlines()) # Answer: 631171 too high # Answer: 628586 print('PartI:', react(reactions)) print('Part II:', findMaximumYield(reactions, ore_quantity=1000000000000))