-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
main.go
38 lines (34 loc) · 761 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"bufio"
"fmt"
"log"
"net/http"
)
func main() {
// get the book moby dick
res, err := http.Get("http://www.gutenberg.org/files/2701/old/moby10b.txt")
if err != nil {
log.Fatal(err)
}
// scan the page
scanner := bufio.NewScanner(res.Body)
defer res.Body.Close()
// Set the split function for the scanning operation.
scanner.Split(bufio.ScanWords)
// Create slice to hold counts
buckets := make([]int, 200)
// Loop over the words
for scanner.Scan() {
n := hashBucket(scanner.Text())
buckets[n]++
}
fmt.Println(buckets[65:123])
// fmt.Println("***************")
// for i := 28; i <= 126; i++ {
// fmt.Printf("%v - %c - %v \n", i, i, buckets[i])
// }
}
func hashBucket(word string) int {
return int(word[0])
}