This is a running series of posts on the Advent of Code 2020. The introductory post has the details, including the accompanying GitHub repo, in case you reached this directly.
Today we process some directions consisting of a command and an argument. We start at (0, 0) in a two-dimensional space, and there are commands of the form direction argument, where direction can be forward, up or down, and the argument is a positive integer. The exact interpretation changes in each part.
Part 1
Part 2
For this part there is a third concept: aim, a sort of heading. up and down now change the heading, and forward moves horizontally by its argument as before, but also vertically by aim times the argument. This forces to track the state step by step, but it's just a matter of having three variables (two for the position, one for the aim) and applying each command with a plain if-elif-else structure.
No comments:
Post a Comment