You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2019/ruby/day_07.rb

13 lines
320 B

require_relative "computer"
program = ARGF.read
puts (0..4).to_a.permutation.map {|phase_settings|
amplifiers = Array.new(5) { Computer.from(program) }
amplifiers.zip(phase_settings).inject(?0) {|i, (a, ps)|
output = StringIO.new
a.run(StringIO.new("#{ps}\n#{i}"), output)
output.string
}.to_i
}.max