Watch
1
0
Fork
You've already forked advent-of-code
0

2019: Day 19 Part 1

This commit is contained in:
Jeremy Kaplan 2019-12-27 18:40:12 -07:00
commit 52dc14a761
2 changed files with 290 additions and 0 deletions

38
2019/day19/part1.rb Normal file
View file

@ -0,0 +1,38 @@
# frozen_string_literal: true
require_relative 'intcode'
Cell = Struct.new(:x, :y)
class Drone
def initialize(program, target)
@computer = Intcode::Computer.new(program.as_memory) { on_input }
@input_queue = [target.x, target.y]
end
def on_input
@input_queue.shift
end
def run
@computer.next_output
end
end
program = Intcode.read(File.join(__dir__, 'input'))
affected = 0
(0...50).each do |y|
(0...50).each do |x|
drone = Drone.new(program, Cell.new(x, y))
case drone.run
when 0
print '.'
when 1
print '#'
affected += 1
end
end
print "\n"
end
puts affected