Learning GO

This commit is contained in:
Zakaria
2026-08-31 14:57:35 -04:00
commit d307eb2698
19 changed files with 310 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
scan := bufio.NewScanner(os.Stdin)
words := make(map[string]int)
scan.Split(bufio.ScanWords)
total := 0
for scan.Scan() {
words[scan.Text()]++
total++
}
fmt.Printf("this file has about %v words and ", total)
fmt.Println(len(words), "Unique words")
type kv struct {
key string
val int
}
var ss []kv
for k, v := range words {
ss = append(ss, kv{k, v})
}
sort.Slice(ss, func(i, j int) bool {
return ss[i].val > ss[j].val
})
for _, s := range ss[:4] {
fmt.Println(s.key, "appears", s.val, "times")
}
}
+3
View File
@@ -0,0 +1,3 @@
module main
go 1.26.5
+1
View File
@@ -0,0 +1 @@
Hello there, Bright morning hikers crossed quiet valleys while curious birds circled overhead. Each traveler carried water, maps, snacks, sturdy boots, and cameras. They discovered ancient stones, fragrant flowers, distant waterfalls, colorful butterflies, mossy bridges, peaceful ponds by sunset. Everyone shared stories, laughter, gratitude, and plans another adventure. Bright morning hikers crossed valleys, while curious birds circled overhead, and everyone shared stories.