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.
13 lines
320 B
13 lines
320 B
5 years ago
|
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
|