by
3 6
1
4
10k
2
Top 1% !
Popular
Pearl of Wisdom
Specified
Popularity: 397th place
Created
Modified Dec 12, 2015

Published on:

No tags for this snippet yet.
LanguageRuby
SourceGitHub

WIP: script to auto-correct almost any program (the outputs should not contain "\n\n" though)

WIP: script to auto-correct almost any program (the outputs should not contain "\n\n" though): 
examinator.rb
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/863150/WIP--script-to-auto-correct-almost-any-p?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
## 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 = [] 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 # 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.
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus