My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow invoking Intcode module as script

+26
+26
2019/intcode.py
··· 1 + #!/usr/bin/env python 1 2 from collections import defaultdict 2 3 3 4 # Potential debug output ··· 145 146 # HALT 146 147 elif op == 99: 147 148 raise StopIteration() 149 + 150 + 151 + if __name__ == '__main__': 152 + import sys 153 + 154 + if len(sys.argv) < 2: 155 + print "Usage: intcode.py <intcode_program> [stdin]" 156 + sys.exit(2) 157 + 158 + with open(sys.argv[1]) as f: 159 + tape = [int(x) for x in f.readlines()[0].split(',')] 160 + 161 + inputs = [] 162 + 163 + if len(sys.argv) >= 3: 164 + with open(sys.argv[2]) as f: 165 + inputs = [int(x) for x in f.readlines()[0].split(',')] 166 + 167 + vm = emulate(tape, inputs) 168 + 169 + try: 170 + while True: 171 + print(next(vm)) 172 + except StopIteration: 173 + pass