Skip to content

Instantly share code, notes, and snippets.

@kenjoe41
Created December 1, 2022 13:25
Show Gist options
  • Save kenjoe41/ac82e36e4cba39434c2c2326681f1b47 to your computer and use it in GitHub Desktop.
Save kenjoe41/ac82e36e4cba39434c2c2326681f1b47 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strings"
)
func main() {
// Use a map to store the unique URL directories we find
dirs := make(map[string]bool)
// Read the URLs from standard input
var url string
for {
// Read the next URL
_, err := fmt.Scanln(&url)
if err != nil {
break
}
// Extract the directory from the URL
parts := strings.Split(url, "/")
dir := strings.Join(parts[:len(parts)-1], "/")
// Add the directory to our map if it's not already there
if !dirs[dir] {
dirs[dir] = true
fmt.Println(dir)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment