r/adventofcode • • Dec 10 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 10 Solutions -πŸŽ„-

THE USUAL REMINDERS


--- Day 10: Cathode-Ray Tube ---


Post your code solution in this megathread.


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:12:17, megathread unlocked!

61 Upvotes

933 comments sorted by

View all comments

2

u/saarin Dec 10 '22
#!/usr/bin/env python

import sys


def main() -> None:
    data = open("input.txt", mode="r").read().splitlines()

    circle_values = []
    current_value = 1

    for row in data:
        if len(row.split()) != 2:
            circle_values.append(current_value)
        else:
            _, value = row.split(" ")

            circle_values.append(current_value)
            circle_values.append(current_value)
            current_value = current_value + int(value)

    print(
        "first part solution",
        circle_values[20 - 1] * 20
        + circle_values[60 - 1] * 60
        + circle_values[100 - 1] * 100
        + circle_values[140 - 1] * 140
        + circle_values[180 - 1] * 180
        + circle_values[220 - 1] * 220,
    )

    for i in range(0, 6):
        for j in range(0, 40):

            if j in [
                circle_values[i * 40 + j],
                circle_values[i * 40 + j] + 1,
                circle_values[i * 40 + j] - 1,
            ]:
                print("#", end="")
            else:
                print(".", end="")
        print("")


if __name__ == "__main__":
    sys.exit(main())

1

u/daggerdragon Dec 10 '22
  1. Next time, use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.
  2. Your code is too long to be posted here directly, so instead of wasting your time fixing the formatting, read our article on oversized code which contains two possible solutions.

Please edit your post to put your code in an external link and link that here instead.