Skip to content

Commit 405536a

Browse files
committed
Initial commit
0 parents  commit 405536a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+601
-0
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = false
9+
max_line_length = 120
10+
tab_width = 4
11+
12+
[{*.bash,*.sh,*.zsh,*.proto,*.pb,*.textproto}]
13+
indent_size = 2
14+
tab_width = 2
15+
16+
[{*.go,*.go2}]
17+
indent_style = tab
18+
19+
[{*.yaml,*.yml,*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}]
20+
indent_size = 2

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/algs4test/testdata/* filter=lfs diff=lfs merge=lfs -text

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# IntelliJ project directories and files
25+
*.iml
26+
*.ipr
27+
*.iws
28+
.idea
29+
30+
# MacOS
31+
.DS_Store

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Calvin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+6

algs4/README.md

+7

algs4/context/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
第 6 章:背景

algs4/fundamentals/euclidean.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package fundamentals
2+
3+
// GCD (Greatest Common Divisor) 「欧几里得算法」求两个非负整数 p 和 q 的最大公约数:
4+
// - 若 q 是 0,则最大公约数为 p;
5+
// - 否则,将 p 除以 q 得到余数 r,p 和 q 的最大公约数即为 q 和 r 的最大公约数。
6+
func GCD(p, q int) int {
7+
if q == 0 {
8+
return p
9+
}
10+
r := p % q
11+
return GCD(q, r)
12+
}

algs4/fundamentals/euclidean_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fundamentals
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestGCD(t *testing.T) {
9+
p, q := 10, 15
10+
t.Logf("(%d, %d) 最大公约数:%d\n", p, q, GCD(p, q))
11+
}
12+
13+
func ExampleGCD() {
14+
p, q := 10, 15
15+
fmt.Printf("(%d, %d) 最大公约数:%d\n", p, q, GCD(p, q))
16+
// Output: (10, 15) 最大公约数:5
17+
}

algs4/fundamentals/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
第 1 章:基础

algs4/graphs/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
第 4 章:图

algs4/searching/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
第 3 章:查找

algs4/sorting/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
第 2 章:排序

algs4/strings/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
第 5 章:字符串
18.9 MB
Binary file not shown.
12.3 MB
Binary file not shown.

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/calvinit/algorithms
2+
3+
go 1.22

internal/algs4test/algs4test.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package algs4test
2+
3+
import "embed"
4+
5+
//go:embed testdata/jobs.txt
6+
var jobs string
7+
8+
//go:embed testdata/jobs.txt
9+
var jobsBytes []byte
10+
11+
//go:embed testdata/list.txt
12+
//go:embed testdata/m?.txt
13+
var listm123FS embed.FS
14+
15+
func GetJobs() string { return jobs }
16+
func GetJobsBytes() []byte { return jobsBytes }
17+
func GetListm123FS() embed.FS { return listm123FS }
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9af2cd60ae6acb50889c266ca715c1423fae89610aeee2f8bcea12fd62dab772
3+
size 128000
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:534efbecd9af8e65dbd934184242872b7345ce1b9cb12d641f3761c0e86a1fb9
3+
size 8000
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:4959668a831f42ae6f02ec0ca3ec50e0f6dc60c0a6b2744f46131d4bae238289
3+
size 8000000
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:55d01ef4dbb3d93cf7b18d171ca94163558cd345f3f19fc974194b0e3e716afd
3+
size 16000
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9fec847c81ace91694a2f8bc176a3b6eb6189e7d8e55ee4900306357da9daca0
3+
size 256000
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a00f5e7a5f66b7368a8e8e77f4f959631dd9003fb2599048eb3590f29017f87a
3+
size 32000

internal/algs4test/testdata/4runs.bin

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:0adc3a78645675db8db0448eddfdd6b5a1b00dc5438555113e5040b5ec3e9e70
3+
size 5
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:eb7ece7f83580209c8a0912cc80737faa498fe4f82c55ea0abf5169b31f4c4eb
3+
size 64000

internal/algs4test/testdata/8ints.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:865cc695fe167c9c920faf85b23046518e8fffe2db04d820c7b8823cd048181e
3+
size 42

internal/algs4test/testdata/DJIA.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:785b54f9b40d8b5c3e37945e2944d29e7dfd397a569405b51a7c91b7bf44f7ef
3+
size 1071673

internal/algs4test/testdata/UPC.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f352c281a840f886035ac3c4fabf1540a308e8b7d7a63355510ffed478dd7d28
3+
size 48077850
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5f8759998bc50f1afa6549f25aa6786d52c6e2f1172ffda616b6a230e3963f4f
3+
size 7

internal/algs4test/testdata/abra.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f57e3a40ea0ca929d7d9687fe9f0d7af99ba7d07caf6ef59954caad1ac5a50f5
3+
size 12
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:87fb289306c0e5e7301b3080d849ea6702f0f717662d94db60fba925777588a0
3+
size 17

internal/algs4test/testdata/amino.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:aec7bda927f7116e65edaee6775236ab234420e64256f9c9a853abea0cc882c2
3+
size 1220
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5333bb0ad617c8b943c5bf9e2a2f468afbb02e3f96b21739d40f79553615ec74
3+
size 442
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5333bb0ad617c8b943c5bf9e2a2f468afbb02e3f96b21739d40f79553615ec74
3+
size 442
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:1a406ed03a8599350ee60a3fc355dc6d26e19691afa3a1753d253fbd3358ed54
3+
size 102825

internal/algs4test/testdata/cards.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:1b024e9bec31b53a724a4bc6468149957258da5258cd9c6101be6f26d1ac087c
3+
size 160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:e92826118ed4ca1a0f3b828ae77954171c8f38214a9b6cc95fa8ab85a3adaa7c
3+
size 20944

internal/algs4test/testdata/ex1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:8b9209edb84f57f185716019fdeae72aa0c94abb2adf6233ae38f96a6f49daf5
3+
size 25

internal/algs4test/testdata/ex2.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9cbf6949fb3c19b0cd9c6f4d2402f65a43a3689481785b9774e4370cd7d2dd56
3+
size 26

internal/algs4test/testdata/ex3.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:e0de55cfadc92f8f143d0b27bbc39474febc956021e8bc67561167fe312ea090
3+
size 25

internal/algs4test/testdata/ex4.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:02d116c743f9654c1ec24d0aec388a5a4b727d7505a51dcd140e3aa9c132c513
3+
size 30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:7aa300e5703f45505df12f395fe80a56a5c43c4528928d6024b8fc2ce7aceeb6
3+
size 33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:eb19e53e626222969bd1f5c1bd917810cab5563f5b837df117fb7c23859fe191
3+
size 6251

internal/algs4test/testdata/in1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9792bc9ccbeebe7e59a790090f07f0761562dc065c85c34cce76aaf76490fbd5
3+
size 7

internal/algs4test/testdata/in2.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:d01d1e234a0ad23fb35a98b0f069f20e323c0e11afb60dbc934a480c0dd7b02a
3+
size 12

internal/algs4test/testdata/ip.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:2ccad5f5b47e08e882aa478f236dd2a197455a28efdb4c2290097ef809516e64
3+
size 12074

internal/algs4test/testdata/jobs.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:127fb0d1564c6f6eb756bfb895a8cae48f5be49e04c4e894cf28ff1cbc2e8237
3+
size 407
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:33113ed4adaed72db117c71850ebf54279091ae322f80a9e6b72997f2d814f52
3+
size 111
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:de18f96b95232db7e974d8eb6d98cd0cd566a7ea23470d344f0a6f1b44db3721
3+
size 14574
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:1c3e2e0f0a56880931d51a0c1341e743e7b9e4038e3e60b60321a6b191ee3c4f
3+
size 105000016
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:4d4d7bb09b7debebdb0bfc795a00767f1135cfee1f86147775e53716d3f473ca
3+
size 375933181
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:64c2199ce2ffe473373021c825ea5d377395bb0f75c4010694406d0f3c9af22b
3+
size 187964942
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:16c67e043ac2fb9be73dc1ca94b3e8517c5aab099fed70a4636f46960192118c
3+
size 104518249
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:55dc64a99235f3d6d329a468be4a1cdf13cc7b1ed0954f0ee51ff6c0f695b81b
3+
size 90000000
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:62ddf8056b1c34b07bdbccd4871ee221bfecb34a22918499e898d7569ed0220b
3+
size 27555926
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5a84e0c320af4ebc6cdeb2bdc82039487b31aa3924a05e01192b9a1c4c585559
3+
size 7000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:fbf468a482af1b8467f33a3205dc8e72710464d9b47bfec3f66dda87f915e6f9
3+
size 129644797

internal/algs4test/testdata/list.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:025fa5e6044b64c5e7fb43b8155d3f3b3678725d167222433a55de7c0403d37e
3+
size 14

internal/algs4test/testdata/m1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f2ab88e9edbee71bd12c9e2b51a734cc2da1156d15a3c820f3b4ab660c90bd48
3+
size 16

internal/algs4test/testdata/m2.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:ce3c5612be2f4641daa45f21ca990575e503da5d4c7322e7598a96328cd2faf5
3+
size 12

internal/algs4test/testdata/m3.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:91ea4eee07019f3160dbbf1a221ea86620d8a064fc98c9aa9234ff9fa66fbfd6
3+
size 12
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:7111cc3468058c96f56ffabaa635c902e870f401f8fe2a003e7b01384dcdc6bb
3+
size 5632
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5b8eca353e6ce5dd0967e6ccc15521f3ed39f3625c578d924355cef48ff87f69
3+
size 890
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:2da39ae100c928868cf50442b03ba4f10db44664969703f59c0e98b117e15eb1
3+
size 40745
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:496e1cc7bbad7e46fc827a56974df961a82d8b34020848f619d58957f796dd71
3+
size 19291
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bb34b54f71ba48d2cdc6acaca28c7ae4c3cdbdfb84d17ad5ea2a70408ea55c23
3+
size 9107
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:8b73cb01cef184becf309861d046bb49fa28b6c9b3223cbbda1eec3b3c1b93b6
3+
size 6904
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:feb943634f3e9d7231e6df29339323d4778011222a9d38bfaba88cc51ed9af8f
3+
size 1191463
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:077018a4288d453bd38b1e1364d710311fdecf16d67a369e6bd9abd3d44452e7
3+
size 3359383

internal/algs4test/testdata/pi.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:d60cf10c50933738492b3f26fe82f58eaf961fea508784820b5e12ca421da9c4
3+
size 100001
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:1691bed2f1629b39b65349c1f8bbb514382798c91ff78237a07b5057edce68d3
3+
size 192
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3da7e26f7d518df05338cf384e4e65e49d3093a14522f613a882d9e14d83fe0e
3+
size 768

internal/algs4test/testdata/rates.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f53989835ddec41797e7246ade46f66df765e082d77b8facf19a3aa093fde958
3+
size 189
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:fb1c61835296e110715bbe4c82e0f9b74ddc847e4d36e90b3badefa93b8411c6
3+
size 144

0 commit comments

Comments
 (0)