[2019][ruby][7.a]

master
Alpha Chen 5 years ago
parent 2c8fca3bd5
commit 631b2642b4

@ -1,5 +1,7 @@
# typed: strict # typed: strict
require "stringio"
require "sorbet-runtime" require "sorbet-runtime"
AnyIO = T.type_alias { T.any(IO, StringIO) } AnyIO = T.type_alias { T.any(IO, StringIO) }

@ -0,0 +1,12 @@
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
Loading…
Cancel
Save