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)
|
||||
}
|
||||
Reference in new issue
Block a user