Last active
August 26, 2019 12:00
-
-
Save devig/3d802cb59b73a4bae039262e7337cd8e to your computer and use it in GitHub Desktop.
weird-faculty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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