lib/judge_system.rb in judge_system-1.4.0 vs lib/judge_system.rb in judge_system-1.5.0
- old
+ new
@@ -1,12 +1,12 @@
require "judge_system/version"
+require 'zlib_input'
require "net/http"
require "uri"
require "json"
require 'timeout'
require 'pathname'
-
module JudgeSystem
class WandBox
def self.compile compiler: "", code: "", stdin: ""
body = {
@@ -14,28 +14,29 @@
compiler: compiler,
stdin: stdin,
}
uri = URI.parse("http://melpon.org/wandbox/api/compile.json")
request = Net::HTTP::Post.new(uri.request_uri, initheader = { "Content-type" => "application/json" },)
- request.body = body.to_json
+ request.body = JSON.generate body
http = Net::HTTP.new(uri.host, uri.port)
http.start do |http|
response = http.request(request)
JSON.parse(response.body)
end
end
def self.run lang, code, input, time
path = File.expand_path('../', __FILE__ )
- sys = File.open("#{path}/compile_systems/#{lang}_system.cpp", "r").read
+ sys = File.open("#{path}/compile_systems/#{lang}_system.rb", "r").read
data = nil
spliter = "\n<$><*><$>\n"
+ input = ZlibInput.zlib(input)
stdin = code + spliter + input + spliter + ("%f" % time)
begin
- data = compile( compiler: "gcc-head", code: sys, stdin: stdin )
- rescue
- return 'RE'
+ data = compile( compiler: "ruby-head", code: sys, stdin: stdin )
+ rescue
+ return "RE"
end
error = data["program_error"]
result = data["program_output"]
if error == "Killed\n"
return 'TLE'
@@ -63,10 +64,10 @@
end
end
end
end
- def judge_result lang: "", code: "" , answer: "", stdin: "", time: 100
+ def judge_result lang: "", code: "" , answer: "", stdin: "", time: 20
WandBox.judge lang, code, answer, stdin, time
end
module_function :judge_result
end