Last active
December 12, 2015 05:38
-
-
Save Drowze/6f107cbde03c6869686f to your computer and use it in GitHub Desktop.
WIP: script to auto-correct almost any program (the outputs should not contain "\n\n" though)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Converting line endings to unix: | |
inputs_file = File.open('./inputs.txt', 'a+') | |
outputs_file = File.open('./outputs.txt', 'a+') | |
input_file_contents = inputs_file.read.gsub(/\r\n?/,"\n") | |
inputs_file.truncate(0) | |
inputs_file.print input_file_contents | |
outputs_file_contents = outputs_file.read.gsub(/\r\n?/,"\n") | |
outputs_file.truncate(0) | |
outputs_file.print outputs_file_contents | |
inputs_file.close | |
outputs_file.close | |
# Getting each input and each output into an array the idea is, basically, | |
# separate them each time we find an empty line ("\n"). | |
# Should be noted though, that since the expected output should contain an | |
# "\n" at its ending, so should each element on our array. | |
inputs_file = File.open('./inputs.txt', 'r') | |
outputs_file = File.open('./outputs.txt', 'r') | |
inputs = [] | |
outputs = [] | |
# Bug: the last input MAY not contain "\n". | |
loop do | |
inputs_contents = inputs_file.gets('') | |
outputs_contents = outputs_file.gets('') | |
if inputs_contents.nil? || outputs_contents.nil? | |
break | |
else | |
inputs_contents.gsub!("\n\n", "\n") | |
outputs_contents.gsub!("\n\n", "\n") | |
inputs << inputs_contents | |
outputs << outputs_contents | |
end | |
end | |
inputs.each { |x| p x} | |
# To continue. Next step: get user's output. | |
# Little snippet on how to get terminal's output below: | |
# test = __FILE__ | |
# puts `ls #{test}`.class # It's a string. | |
# # snippet on how to get timeout on a faulty code: | |
# Timeout.timeout(1) { `gcc faulty_code.c < some_input` } | |
# # => Timeout::Error: execution expired |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment