mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-16 10:11:15 +00:00
first
This commit is contained in:
39
course/9-maps/exercises/4-maps_count/code.go
Normal file
39
course/9-maps/exercises/4-maps_count/code.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func getCounts(userIDs []string) map[string]int {
|
||||
// ?
|
||||
}
|
||||
|
||||
// don't edit below this line
|
||||
|
||||
func test(userIDs []string, ids []string) {
|
||||
fmt.Printf("Generating counts for %v user IDs...\n", len(userIDs))
|
||||
|
||||
counts := getCounts(userIDs)
|
||||
fmt.Println("Counts from select IDs:")
|
||||
for _, k := range ids {
|
||||
v := counts[k]
|
||||
fmt.Printf(" - %s: %d\n", k, v)
|
||||
}
|
||||
fmt.Println("=====================================")
|
||||
}
|
||||
|
||||
func main() {
|
||||
userIDs := []string{}
|
||||
for i := 0; i < 10000; i++ {
|
||||
h := md5.New()
|
||||
io.WriteString(h, fmt.Sprint(i))
|
||||
key := fmt.Sprintf("%x", h.Sum(nil))
|
||||
userIDs = append(userIDs, key[:2])
|
||||
}
|
||||
|
||||
test(userIDs, []string{"00", "ff", "dd"})
|
||||
test(userIDs, []string{"aa", "12", "32"})
|
||||
test(userIDs, []string{"bb", "33"})
|
||||
}
|
||||
Reference in New Issue
Block a user