Quick actions

cmd+k|ctrl+k

Navigation

Languages

aoc2017day05-2

Snippet info

Language

Python

Visibility

public

Author

christophe.guillon.perso

Created

2017-12-05T05:41:47Z

Updated

2017-12-05T05:42:09Z

import sys

def day5_2(input):
    maze = list(map(lambda x: int(x.rstrip()), input.split()))
    size = len(maze)
    steps = 0
    pc = 0
    while pc >= 0 and pc < size:
        offset = maze[pc]
        if offset >= 3: maze[pc] -= 1
        else: maze[pc] += 1
        pc += offset
        steps += 1
    return "%d" % steps

input = sys.stdin.read()
print(day5_2(input))
INFO