Skip to content

Instantly share code, notes, and snippets.

@dryleaf
Last active May 27, 2018 23:00
Show Gist options
  • Save dryleaf/d9f6b8c1e23a483387410aa2b599eb1b to your computer and use it in GitHub Desktop.
Save dryleaf/d9f6b8c1e23a483387410aa2b599eb1b to your computer and use it in GitHub Desktop.
HDE programming challenge
package main
import (
"fmt"
"bytes"
"strconv"
)
func main() {
var N int
fmt.Scanln(&N)
readCases(N)
fmt.Print(buffer.String())
}
var buffer bytes.Buffer
func readCases(N int) {
if N == 0 {
return
}
var X int
fmt.Scanln(&X)
buffer.WriteString(strconv.Itoa(readXs(X))+"\n")
readCases(N - 1)
}
func readXs(x int) int {
if x == 0 {
return 0
}
var y int
fmt.Scanf("%d", &y)
if y >= 0 {
return y * y + readXs(x - 1)
} else {
return readXs(x - 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment