Sparrow1029

Advent of Code 2017 - Day 5 - Python 3

Dec 5th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. """Day 5 -- Advent of Code 2017"""
  5.  
  6. # Open and parse input to form our list of jump instructions.
  7. with open('Day5input.txt', 'r') as f:
  8.     instructions = list(map(int, [s.strip() for s in f.readlines()]))
  9.  
  10. # test = [0, 3, 0, 1, -3]
  11. # instructions = test
  12. cnt = 0
  13. cur_index = 0
  14. while True:
  15.     # print(test)
  16.     try:
  17.         jump_val = instructions[cur_index]
  18.         next_index = cur_index + jump_val
  19.         # instructions[cur_index] += 1  # PART ONE
  20.         instructions[cur_index] += (-1 if jump_val >= 3 else 1)  # PART TWO
  21.         cur_index = next_index
  22.     except IndexError:
  23.         break
  24.     cnt += 1
  25.  
  26. print(cnt)
Advertisement
Add Comment
Please, Sign In to add comment