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)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
unused := 1
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Split(bufio.ScanWords)
|
||||
var total, count float64
|
||||
for scanner.Scan() {
|
||||
value, err := strconv.ParseFloat(scanner.Text(), 64)
|
||||
if err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
total += value
|
||||
count++
|
||||
}
|
||||
fmt.Printf("%.9f\n", total/count)
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
var target int
|
||||
if _, err := fmt.Fscan(reader, &target); err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
seen := map[int]int{}
|
||||
scanner := bufio.NewScanner(reader)
|
||||
scanner.Split(bufio.ScanWords)
|
||||
for position := 1; scanner.Scan(); position++ {
|
||||
value, err := strconv.Atoi(scanner.Text())
|
||||
if err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
if first, ok := seen[target-value]; ok {
|
||||
fmt.Println(first, position)
|
||||
return
|
||||
}
|
||||
if _, ok := seen[value]; !ok {
|
||||
seen[value] = position
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// Wrong: always answers the first two positions.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(1, 2)
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Split(bufio.ScanWords)
|
||||
total := new(big.Int)
|
||||
for scanner.Scan() {
|
||||
value, ok := new(big.Int).SetString(scanner.Text(), 10)
|
||||
if !ok {
|
||||
os.Exit(2)
|
||||
}
|
||||
total.Add(total, value)
|
||||
}
|
||||
fmt.Println(total)
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// Wrong: int64 overflows, so only the group with huge numbers fails.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Split(bufio.ScanWords)
|
||||
var total int64
|
||||
for scanner.Scan() {
|
||||
value, err := strconv.ParseInt(scanner.Text(), 10, 64)
|
||||
if err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
total += value
|
||||
}
|
||||
fmt.Println(total)
|
||||
}
|
||||
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"schema": "lincodex.runner-judge-fixtures/v1",
|
||||
"description": "Reference solutions in Python and Go with their expected outcome per test group. Each task has one public and three hidden groups; checkers.program names a checker source under this directory.",
|
||||
"limits": {"time_limit_ms": 2000, "memory_limit_mb": 128, "output_limit_kb": 64},
|
||||
"tasks": [
|
||||
{
|
||||
"name": "sum",
|
||||
"groups": [
|
||||
{"id": "public", "visibility": "public", "checker": {"kind": "exact"}, "tests": [
|
||||
{"id": "t1", "input": "1 2 3\n", "expected_output": "6\n"}]},
|
||||
{"id": "hidden-1", "visibility": "hidden", "checker": {"kind": "exact"}, "tests": [
|
||||
{"id": "t1", "input": "5 5\n", "expected_output": "10\n"},
|
||||
{"id": "t2", "input": "100\n", "expected_output": "100\n"}]},
|
||||
{"id": "hidden-2", "visibility": "hidden", "checker": {"kind": "tokens"}, "tests": [
|
||||
{"id": "t1", "input": "-1 -2\n", "expected_output": "-3"},
|
||||
{"id": "t2", "input": "-5 5\n", "expected_output": "0"}]},
|
||||
{"id": "hidden-3", "visibility": "hidden", "checker": {"kind": "exact"}, "tests": [
|
||||
{"id": "t1", "input": "9000000000000000000 9000000000000000000\n", "expected_output": "18000000000000000000\n"}]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mean",
|
||||
"groups": [
|
||||
{"id": "public", "visibility": "public", "checker": {"kind": "numbers", "abs_tolerance": 1e-6}, "tests": [
|
||||
{"id": "t1", "input": "1 2 7\n", "expected_output": "3.333333333\n"}]},
|
||||
{"id": "hidden-1", "visibility": "hidden", "checker": {"kind": "numbers", "abs_tolerance": 1e-6}, "tests": [
|
||||
{"id": "t1", "input": "1 2\n", "expected_output": "1.5\n"},
|
||||
{"id": "t2", "input": "4 6\n", "expected_output": "5\n"}]},
|
||||
{"id": "hidden-2", "visibility": "hidden", "checker": {"kind": "numbers", "rel_tolerance": 1e-9}, "tests": [
|
||||
{"id": "t1", "input": "10 20 31\n", "expected_output": "20.3333333333\n"}]},
|
||||
{"id": "hidden-3", "visibility": "hidden", "checker": {"kind": "numbers", "abs_tolerance": 1e-6}, "tests": [
|
||||
{"id": "t1", "input": "1\n", "expected_output": "1\n"}]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pair",
|
||||
"groups": [
|
||||
{"id": "public", "visibility": "public", "checker": {"kind": "custom", "program": {"language": "python3", "source": "checkers/pair_checker.py"}}, "tests": [
|
||||
{"id": "t1", "input": "9\n2 7 11 15\n", "expected_output": "1 2\n"}]},
|
||||
{"id": "hidden-1", "visibility": "hidden", "checker": {"kind": "custom", "program": {"language": "python3", "source": "checkers/pair_checker.py"}}, "tests": [
|
||||
{"id": "t1", "input": "6\n3 2 4\n", "expected_output": "2 3\n"}]},
|
||||
{"id": "hidden-2", "visibility": "hidden", "checker": {"kind": "custom", "program": {"language": "go", "source": "checkers/pair_checker.go"}}, "tests": [
|
||||
{"id": "t1", "input": "10\n5 5 1\n", "expected_output": "1 2\n"}]},
|
||||
{"id": "hidden-3", "visibility": "hidden", "checker": {"kind": "custom", "program": {"language": "go", "source": "checkers/pair_checker.go"}}, "tests": [
|
||||
{"id": "t1", "input": "0\n-3 4 3 90\n", "expected_output": "1 3\n"}]}
|
||||
]
|
||||
}
|
||||
],
|
||||
"solutions": [
|
||||
{"name": "python_sum_correct", "task": "sum", "language": "python3", "source": "python/sum_correct.py",
|
||||
"expect": {"outcome": "accepted", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "accepted"}}},
|
||||
{"name": "python_sum_drops_signs", "task": "sum", "language": "python3", "source": "python/sum_drops_signs.py",
|
||||
"expect": {"outcome": "wrong_answer", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "wrong_answer", "hidden-3": "accepted"}}},
|
||||
{"name": "go_sum_correct", "task": "sum", "language": "go", "source": "go/sum_correct.go",
|
||||
"expect": {"outcome": "accepted", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "accepted"}}},
|
||||
{"name": "go_sum_overflows", "task": "sum", "language": "go", "source": "go/sum_overflows.go",
|
||||
"expect": {"outcome": "wrong_answer", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "wrong_answer"}}},
|
||||
{"name": "go_compile_error", "task": "sum", "language": "go", "source": "go/compile_error.go",
|
||||
"expect": {"outcome": "compile_error", "groups": {"public": "compile_error", "hidden-1": "compile_error", "hidden-2": "compile_error", "hidden-3": "compile_error"}}},
|
||||
{"name": "python_mean_full_precision", "task": "mean", "language": "python3", "source": "python/mean_full_precision.py",
|
||||
"expect": {"outcome": "accepted", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "accepted"}}},
|
||||
{"name": "python_mean_two_decimals", "task": "mean", "language": "python3", "source": "python/mean_two_decimals.py",
|
||||
"expect": {"outcome": "wrong_answer", "groups": {"public": "wrong_answer", "hidden-1": "accepted", "hidden-2": "wrong_answer", "hidden-3": "accepted"}}},
|
||||
{"name": "go_mean_nine_decimals", "task": "mean", "language": "go", "source": "go/mean_nine_decimals.go",
|
||||
"expect": {"outcome": "accepted", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "accepted"}}},
|
||||
{"name": "python_pair_correct", "task": "pair", "language": "python3", "source": "python/pair_correct.py",
|
||||
"expect": {"outcome": "accepted", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "accepted"}}},
|
||||
{"name": "go_pair_correct", "task": "pair", "language": "go", "source": "go/pair_correct.go",
|
||||
"expect": {"outcome": "accepted", "groups": {"public": "accepted", "hidden-1": "accepted", "hidden-2": "accepted", "hidden-3": "accepted"}}},
|
||||
{"name": "go_pair_first_two", "task": "pair", "language": "go", "source": "go/pair_first_two.go",
|
||||
"expect": {"outcome": "wrong_answer", "groups": {"public": "accepted", "hidden-1": "wrong_answer", "hidden-2": "accepted", "hidden-3": "wrong_answer"}}}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import sys
|
||||
|
||||
values = [int(token) for token in sys.stdin.read().split()]
|
||||
print(sum(values) / len(values))
|
||||
@@ -0,0 +1,5 @@
|
||||
# Wrong: rounds to two decimals, so only exact means pass the tolerance.
|
||||
import sys
|
||||
|
||||
values = [int(token) for token in sys.stdin.read().split()]
|
||||
print(f"{sum(values) / len(values):.2f}")
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# Prints any pair of 1-based positions whose values add up to the target.
|
||||
import sys
|
||||
|
||||
lines = sys.stdin.read().split("\n")
|
||||
target = int(lines[0])
|
||||
values = [int(token) for token in lines[1].split()]
|
||||
seen = {}
|
||||
for position, value in enumerate(values, start=1):
|
||||
if target - value in seen:
|
||||
print(seen[target - value], position)
|
||||
break
|
||||
seen.setdefault(value, position)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import sys
|
||||
|
||||
print(sum(int(token) for token in sys.stdin.read().split()))
|
||||
@@ -0,0 +1,4 @@
|
||||
# Wrong: adds absolute values, so only groups with negative numbers fail.
|
||||
import sys
|
||||
|
||||
print(sum(abs(int(token)) for token in sys.stdin.read().split()))
|
||||
Reference in new issue
Block a user