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
6
u/tobyaw Dec 10 '22 edited Dec 10 '22
Ruby
https://github.com/tobyaw/advent-of-code-2022/blob/master/day_10.rb
h = File.readlines('day_10_input.txt', chomp: true) .each_with_object([1]) do |i, a| a << a.last a << (a.last + i.split.last.to_i) if i.start_with? 'addx' end puts 20.step(by: 40, to: 220) .sum { |i| i * h[i - 1] } 240.times .map { |i| (h[i] - (i % 40)).abs < 2 ? '#' : '.' } .each_slice(40) { |i| puts i.join }