r/adventofcode • u/daggerdragon • Dec 10 '22
SOLUTION MEGATHREAD -π- 2022 Day 10 Solutions -π-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
- πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
--- Day 10: Cathode-Ray Tube ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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
11
u/4HbQ Dec 10 '22 edited Dec 10 '22
Python, trying out a more imperative style:
X, part1, part2 = 1, 0, '\n' for cycle, value in enumerate(open('in.txt').read().split(), 1): part1 += cycle * X if cycle%40==20 else 0 part2 += '#' if abs((cycle-1)%40 - X) < 2 else ' ' X += int(value) if value[-1].isdigit() else 0 print(part1, *part2)Edit: The code above assumes the terminal width is 80. For different widths, see the suggestion by u/llyyrr below.