feat(runner): compile Go and check answers per test group
This commit is contained in:
1 parent
e95c681165
commit
afee564bf4
61 files changed
+2592
-143
No files matched your search
+39
@@ -0,0 +1,39 @@
|
||||
// Custom checker of the pair task in Go, with the same rules as
|
||||
// pair_checker.py.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
input, err := os.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
os.Exit(3)
|
||||
}
|
||||
actual, err := os.ReadFile(os.Args[3])
|
||||
if err != nil {
|
||||
os.Exit(3)
|
||||
}
|
||||
lines := strings.Split(string(input), "\n")
|
||||
target, _ := strconv.Atoi(strings.TrimSpace(lines[0]))
|
||||
var values []int
|
||||
for _, field := range strings.Fields(lines[1]) {
|
||||
value, _ := strconv.Atoi(field)
|
||||
values = append(values, value)
|
||||
}
|
||||
answer := strings.Fields(string(actual))
|
||||
if len(answer) != 2 {
|
||||
os.Exit(1)
|
||||
}
|
||||
first, errFirst := strconv.Atoi(answer[0])
|
||||
second, errSecond := strconv.Atoi(answer[1])
|
||||
valid := errFirst == nil && errSecond == nil && first != second &&
|
||||
first >= 1 && first <= len(values) && second >= 1 && second <= len(values)
|
||||
if valid && values[first-1]+values[second-1] == target {
|
||||
os.Exit(0)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
# Custom checker of the pair task: accepts any two distinct 1-based
|
||||
# positions whose values add up to the target. Exit 0 accepts, 1 rejects.
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1]) as stream:
|
||||
lines = stream.read().split("\n")
|
||||
with open(sys.argv[3]) as stream:
|
||||
answer = stream.read().split()
|
||||
target = int(lines[0])
|
||||
values = [int(token) for token in lines[1].split()]
|
||||
try:
|
||||
first, second = (int(token) for token in answer)
|
||||
except ValueError:
|
||||
sys.exit(1)
|
||||
valid = 1 <= first <= len(values) and 1 <= second <= len(values) and first != second
|
||||
sys.exit(0 if valid and values[first - 1] + values[second - 1] == target else 1)
|
||||
Reference in new issue
Block a user