-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
69 lines (51 loc) · 1.54 KB
/
update.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
)
var base = `GoLeet
======
My collection of leet code problems solved in GoLang!
Link to profile, [bhargavsnv100](https://leetcode.com/bhargavsnv100/)
| [Easy](Easy/README.md) | [Medium](Medium/README.md) | [Hard](Hard/README.md) |
|------------------------|----------------------------|------------------------|
| %v | %v | %v |
Problems finished
=================
`
func main() {
dirs := []string{"Easy", "Medium", "Hard"}
count := []int{0, 0, 0}
readmeData := ""
for i, dir := range dirs {
readmeData += fmt.Sprintf("\n%s\n%s\n\n", dir, strings.Repeat("-", len(dir)))
// Remove Problem Directory Readme
readme := fmt.Sprintf("./%s/README.md", dir)
os.Remove("./" + dir + "/README.md")
// Get files in directory
files, err := ioutil.ReadDir("./" + dir + "/")
if err != nil {
log.Fatal(err)
}
// Get count of files
count[i] = len(files)
// Populate list of solved problems
data := fmt.Sprintf("%s\n%s\n\n", dir, strings.Repeat("=", len(dir)))
for _, file := range files {
row := fmt.Sprintf("- [%s](%s/%s)\n", file.Name(), dir, file.Name())
data += strings.ReplaceAll(row, dir+"/", "")
readmeData += row
}
// Write problem directory readme
err = ioutil.WriteFile(readme, []byte(data), 0644)
if err != nil {
log.Fatal(err)
}
}
base = fmt.Sprintf(base, count[0], count[1], count[2])
readmeData = base + readmeData
ioutil.WriteFile("README.md", []byte(readmeData), 0644)
}