aboutsummaryrefslogtreecommitdiff
path: root/store/works/life/lanqiao-selection-match/check-out.rb
diff options
context:
space:
mode:
Diffstat (limited to 'store/works/life/lanqiao-selection-match/check-out.rb')
-rwxr-xr-xstore/works/life/lanqiao-selection-match/check-out.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/store/works/life/lanqiao-selection-match/check-out.rb b/store/works/life/lanqiao-selection-match/check-out.rb
new file mode 100755
index 0000000..b1ce29c
--- /dev/null
+++ b/store/works/life/lanqiao-selection-match/check-out.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+
+require 'csv'
+
+$result = {}
+$answer = {
+ 'A' => [9, 11, 9],
+ 'B' => [10_199_346, 872_919_755, 21_850_795_004],
+ 'C' => [91, 898, 9006, 89_794]
+}
+
+# @param student_no [String]
+# @param question_no [String]
+# @param answer [Array]
+def check(student_no, question_no, test_no)
+ out_file = "./out/#{student_no}#{question_no}-#{test_no}.out"
+ if File.read(out_file).to_i == $answer[question_no][test_no - 1]
+ $result[student_no] ||= []
+ $result[student_no] << "#{question_no}-#{test_no}"
+ end
+end
+
+Dir.entries('./out').each do |f|
+ next if ['.', '..'].include?(f)
+
+ /(\d+)([ABC])-(\d)\.out/ =~ f
+ if Regexp.last_match.nil?
+ puts "Error: #{f}"
+ exit 1
+ end
+
+ check(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3).to_i)
+end
+
+CSV.open('./result.csv', 'w') do |csv|
+ qs = %w[A-1 A-2 A-3 B-1 B-2 B-3 C-1 C-2 C-3 C-4]
+ csv << (['student no'] + qs)
+ $result.each do |student_no, questions|
+ csv << ([student_no] + qs.map { |q| questions.include?(q) ? 1 : 0 })
+ end
+end