Last active
December 22, 2015 02:59
-
-
Save dyoo/6407562 to your computer and use it in GitHub Desktop.
More play with Go. A question from reading Barry Schwartz's "The Paradox of Choice": how many English words start with 't', and how many have 't' as the third letter?
This file contains hidden or 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 | |
// A question from reading Barry Schwartz's "The Paradox of Choice". | |
// | |
// How many English words start with "t"? | |
// | |
// How many English words have "t" as the third letter? | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
count1, count2 := 0, 0 | |
for scanner.Scan() { | |
s := scanner.Text() | |
if len(s) > 0 && (s[0] == 't' || s[0] == 'T') { | |
count1++ | |
} | |
if len(s) > 2 && (s[2] == 't' || s[2] == 'T') { | |
count2++ | |
} | |
} | |
fmt.Println(count1) | |
fmt.Println(count2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment