2 Solutions again.
Go:
package main import ( "bytes" "fmt" "io/ioutil" "os" ) func countQuestions(group []byte) (int, int) { counts := map[byte]int{} numPeople := 1 for _, question := range group { if question == '\n' { numPeople++ } else { counts[question]++ } } numAllYes := 0 for _, c := range counts { if c == numPeople { numAllYes++ } } return len(counts), numAllYes } func main() { input, _ := ioutil.ReadAll(os.Stdin) groups := bytes.Split(input, []byte("\n\n")) sum1, sum2 := 0, 0 for _, group := range groups { a, b := countQuestions(group) sum1 += a sum2 += b } fmt.Println(sum1, sum2) }
And tweet-sized PHP:
<?for($i=0,$z=explode(" ",file_get_contents('input'));$z[$i];){$a+=count($f=count_chars($z[$i++],1))-(($n=$f[10])>0);foreach($f as$k=>$v)$b+=$k!=10&$v==$n+1;}echo"$a $b";
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
2 Solutions again.
Go:
And tweet-sized PHP: