Skip to content

Instantly share code, notes, and snippets.

@mayth
Created July 20, 2014 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayth/f162efa8dc06cd05e5e3 to your computer and use it in GitHub Desktop.
Save mayth/f162efa8dc06cd05e5e3 to your computer and use it in GitHub Desktop.
amida solver (SECCON 2014 Online Preliminary)
def read_problem(io)
problem = ''
loop {
ch = io.getc
break if !ch || ch == '?'
problem << ch
}
io.getc
problem
end
answers = []
def playback(answers, io)
answers.each do |ans|
read_problem(io)
io.puts ans
io.flush
end
end
n = 1
pnum = 1
loop do
open('|./amida_mod', 'a+') do |io|
playback(answers, io)
loop do
problem = read_problem(io)
IO.write("amida2_problem_#{pnum}", problem)
io.puts n
io.flush
result = io.gets
if result.include?('Wrong')
n += 1
break
elsif !result.include?('No.')
puts ">>> #{result}"
end
answers << n
n = 1
puts
warn "solved: #{pnum}"
pnum += 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment