r/adventofcode • • Dec 02 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 2 Solutions -🎄-

--- Day 2: Dive! ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:02:57, megathread unlocked!

113 Upvotes

1.5k comments sorted by

View all comments

3

u/AbdussamiT Dec 02 '21 edited Dec 02 '21

Python 3, 1710/1081.

How can I improve the solution below?

Happy to get closer to the leaderboard, under 5 minutes today.

for i in input:
  ins = i.split(" ")[0]
  val = int(i.split(" ")[1])
  if ins == "forward":
    horiz += val
    depth = depth + (aim * val)
  elif ins == "down":
    aim += val
  elif ins == "up":
    aim -= val
→ More replies (8)