Advertisement
hwright

Day2Part1PythonStarter

Dec 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. def main():
  4.  
  5.     with open("test.txt", 'r') as f:
  6.         lines = f.readlines()
  7.  
  8.         for line in lines:
  9.             line = line.strip("\n") # remove the newline character
  10.             program = line.split(',')
  11.  
  12.             print ("input %s" % program)
  13.  
  14.             position = 0
  15.  
  16.             # loop through the program
  17.             while position < len(program):
  18.                 # get the current opcode
  19.                 opcode = program[position]
  20.  
  21.                 print ("position %s" % position)
  22.                 print ("opcode %s" % opcode)
  23.  
  24.                 # perform action for opcode here
  25.  
  26.                 # skip to the next opcode
  27.                 position = position + 4;
  28.  
  29.             print ("output %s" % program)
  30.  
  31. if __name__ == "__main__":
  32.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement