is this golang implementation correct accordingly to the instruction: Description
The input will be a list of integers, each separated by a newline character.
The first line of the input will be an integer N (1 <= N <= 100), indicating the number of test cases to follow.
Each of the test cases will consist of a line with an integer X (0 < X <= 100), followed by another line consisting of X number of space-separated integers Yn (-100 <= Yn <= 100).
For each test case, calculate the power of four of Yn, excluding when Yn is positive, and print the calculated sum in the output.
Note: There should be no output until all the input has been received.
Note 2: Do not put blank lines between test cases solutions.
Note 3: Take input from standard input, and output to standard output.
Note 4: The final output is guaranteed to be within the int32 range.
Note 5: It is possible that X and the number of integers Yn may not be equal. If that is the case, print -1 as the output.
Rules
Write your solution using Go Programming Language or Python Programming Language. Do not submit your solution with both languages at once!
You may only use standard library packages. In addition, an extra point is awarded if the solution does not declare any global variables.
Specific rules for Go solution
Your source code must be a single file.
Do not use any for and goto statements.
Your solution will be tested against Go 1.24 (as of March 2025) or higher.
package main
func main() {
...
}
Specific rules for Python solution
Your source code must be a single file, including at least a main function.
Do not use any for loop, while loop, or any list / set / dictionary comprehension.
Your solution will be tested against Python 3.13 (as of January 2025) or higher.
def main():
...
if name == "main":
main()
Sample Input
2
4
3 -1 1 10
5
9 -5 -5 -10 10
Sample Output
1
11250
package main
import "fmt"
func main() {
var numberOfTestCases int
fmt.Scan(&numberOfTestCases)
results := processTestCases(numberOfTestCases, []int{})
printResults(results, 0)
}
// Process all test cases recursively
func processTestCases(remaining int, results []int) []int {
if remaining <= 0 {
return results
}
// Read X (number of integers for this test case)
var x int
fmt.Scan(&x)
// Calculate sum of squares for this test case
sum := readAndCalculateSumOfSquares(x, 0)
// Add sum to results
results = append(results, sum)
// Process next test case
return processTestCases(remaining-1, results)
}
// Read integers and calculate sum of squares recursively
func readAndCalculateSumOfSquares(remaining int, sum int) int {
if remaining <= 0 {
return sum
}
var num int
fmt.Scan(&num)
// Only add square if number is non-negative
if num >= 0 {
sum += num * num
}
// Process next integer
return readAndCalculateSumOfSquares(remaining-1, sum)
}
// Recursively print the results
func printResults(result []int, index int) {
if index >= len(result) {
return
}
fmt.Println(result[index])
printResults(result, index+1)
}