Skip to content

Instantly share code, notes, and snippets.

@devig
Last active August 26, 2019 12:00
Show Gist options
  • Save devig/3d802cb59b73a4bae039262e7337cd8e to your computer and use it in GitHub Desktop.
Save devig/3d802cb59b73a4bae039262e7337cd8e to your computer and use it in GitHub Desktop.
weird-faculty
package main
import (
"fmt"
"os"
)
//https://fizzbuzzer.com/weird-faculty/
func main() {
answers := []int{1, 0, 0, 0, 1, 1, 0}
summ := summAnswers(answers) //далее в цикле summ по сути будет friendScore
if summ < 0 {
fmt.Println("You must answer on 0 question!")
os.Exit(0)
}
var youScore int
for key, value := range answers {
if value == 0 {
youScore--
summ++
} else {
youScore++
summ--
}
if youScore > summ {
fmt.Printf("You must answer on %v question!", key+1)
break
}
}
}
func summAnswers(answers []int) int {
var summ int
for _, value := range answers {
if value == 0 {
summ--
} else {
summ++
}
}
return summ
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment