Skip to content

Commit 5ea23c9

Browse files
committedJun 9, 2024
Merge branch 'develop'
2 parents 9e4316a + 0653380 commit 5ea23c9

File tree

11 files changed

+206
-14
lines changed

11 files changed

+206
-14
lines changed
 

‎.github/workflows/cmake.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ on:
66
# branches:
77
# - main
88
# paths:
9-
# - "cpp-algorithm/**"
9+
# - 'cpp-algorithm/**'
1010
# schedule:
11-
# - cron: "0 0 * * *"
11+
# - cron: '0 0 * * *'
1212
workflow_dispatch:
1313

1414
env:

‎.github/workflows/go.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Go Test
3+
4+
on:
5+
# push:
6+
# branches:
7+
# - main
8+
# paths:
9+
# - 'go-algorithm/**'
10+
# schedule:
11+
# - cron: '0 0 * * *'
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Setup Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: '1.22'
25+
26+
- name: Test
27+
working-directory: ${{github.workspace}}/go-algorithm
28+
run: go test -v ./...

‎.github/workflows/gradle.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ on:
66
# branches:
77
# - main
88
# paths:
9-
# - "java-algorithm/**"
9+
# - 'java-algorithm/**'
1010
# schedule:
11-
# - cron: "0 0 * * *"
11+
# - cron: '0 0 * * *'
1212
workflow_dispatch:
1313

1414
jobs:
@@ -21,8 +21,8 @@ jobs:
2121
- name: Setup JDK
2222
uses: actions/setup-java@v4
2323
with:
24-
distribution: "zulu"
25-
java-version: "21"
24+
distribution: 'temurin'
25+
java-version: '21'
2626

2727
- name: Setup Gradle
2828
uses: gradle/gradle-build-action@v3

‎.github/workflows/poetry.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ on:
66
# branches:
77
# - main
88
# paths:
9-
# - "python-algorithm/**"
9+
# - 'python-algorithm/**'
1010
# schedule:
11-
# - cron: "0 0 * * *"
11+
# - cron: '0 0 * * *'
1212
workflow_dispatch:
1313

1414
jobs:
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Python
2222
uses: actions/setup-python@v5
2323
with:
24-
python-version: "3.11"
24+
python-version: '3.12'
2525

2626
- name: Install dependencies
2727
working-directory: ${{github.workspace}}/python-algorithm

‎README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<!-- markdownlint-disable MD033 MD036 -->
44

5-
![C++ CMake Test](https://github.com/codejsha/algorithm-examples/actions/workflows/cmake.yml/badge.svg) ![Python Poetry Test](https://github.com/codejsha/algorithm-examples/actions/workflows/poetry.yml/badge.svg) ![Java Gradle Test](https://github.com/codejsha/algorithm-examples/actions/workflows/gradle.yml/badge.svg)
5+
![C++ CMake Test](https://github.com/codejsha/algorithm-examples/actions/workflows/cmake.yml/badge.svg) ![Python Poetry Test](https://github.com/codejsha/algorithm-examples/actions/workflows/poetry.yml/badge.svg) ![Java Gradle Test](https://github.com/codejsha/algorithm-examples/actions/workflows/gradle.yml/badge.svg) ![Go Test](https://github.com/codejsha/algorithm-examples/actions/workflows/go.yml/badge.svg)
66

77
[English](README.md) | [Korean](README_ko-KR.md)
88

9-
This repository is an implementation of algorithms, data structures, and problem-solving. These are written in C++, Python, and Java, and each language uses the following test framework: [Google Test](https://google.github.io/googletest/)(C++), [pytest](https://docs.pytest.org/)(Python), [JUnit](https://junit.org/)(Java). Run tests to perform methods/functions on the algorithmic logic.
9+
This repository is an implementation of algorithms, data structures, and problem-solving. These are written in C++, Python, Java, and Go, and each language uses the following test framework/package: [Google Test](https://google.github.io/googletest/)(C++), [pytest](https://docs.pytest.org/)(Python), [JUnit](https://junit.org/)(Java), [go test](https://pkg.go.dev/cmd/go)(Go). Run tests to perform methods/functions on the algorithmic logic.
1010

1111
## Project Environments
1212

@@ -15,6 +15,7 @@ Each project is configured in specific environments, as described below:
1515
- C++ project: C++20 / [CMake](https://cmake.org/) build / [GNU Scientific Library (GSL)](https://www.gnu.org/software/gsl/), [Google Test](https://google.github.io/googletest/), [Google Benchmark](https://github.com/google/benchmark), [fmt](https://github.com/fmtlib/fmt) packages / [vcpkg](https://github.com/microsoft/vcpkg) package manager
1616
- Python project: Python 3.11 / [Poetry](https://python-poetry.org/) build / [NumPy](https://numpy.org/), [SciPy](https://www.scipy.org/), [NetworkX](https://networkx.org/), [pytest](https://docs.pytest.org/), [pytest-benchmark](https://pytest-benchmark.readthedocs.io/en/latest/) packages
1717
- Java project: Java 21 / [Gradle](https://gradle.org/) build / [Google Guava](https://github.com/google/guava), [JUnit](https://junit.org/), [Java Microbenchmark Harness (JMH)](https://github.com/openjdk/jmh) libraries
18+
- Go project: Go 1.22 / Go build / [Testify](https://github.com/stretchr/testify) package
1819

1920
## Table of Contents
2021

@@ -868,7 +869,7 @@ Math.abs(-34.5), Math.ceil(2.17), Math.floor(3.14), Math.max(x, -3), Math.min(x,
868869

869870
- Combination: [c++](cpp-algorithm/src/math)(`GenerateCombination`) | Find the number of ways to choose $k$ items from $n$ items.
870871
- Fast Fourier transform: Fast Fourier transform is a mathematical algorithm that finds the discrete Fourier transform of a set of real numbers.
871-
- Greatest common divisor (GCD), CLRS#31.2: [python](python-algorithm/algorithm/math), [java](java-algorithm/src/main/java/com/example/algorithm/math) | Find the greatest common divisor of two numbers.
872+
- Greatest common divisor (GCD), CLRS#31.2: [python](python-algorithm/algorithm/math), [java](java-algorithm/src/main/java/com/example/algorithm/math), [go](go-algorithm/internal/math) | Find the greatest common divisor of two numbers.
872873
- Integer factorization: [c++](cpp-algorithm/src/math), [java](java-algorithm/src/main/java/com/example/algorithm/math) | Integer factorization is the process of determining which prime numbers divide a given positive integer.
873874
- Least common multiple (LCM): [python](python-algorithm/algorithm/math), [java](java-algorithm/src/main/java/com/example/algorithm/math) | Find the least common multiple of two numbers.
874875
- Miller-Rabin primality test, CLRS#31.8: [c++](cpp-algorithm/src/math) | Miller-Rabin primality test is a mathematical algorithm that finds whether a given number is prime.

‎README_ko-KR.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<!-- markdownlint-disable MD033 MD036 -->
44

5-
![C++ CMake Test](https://github.com/codejsha/algorithm-examples/actions/workflows/cmake.yml/badge.svg) ![Python Poetry Test](https://github.com/codejsha/algorithm-examples/actions/workflows/poetry.yml/badge.svg) ![Java Gradle Test](https://github.com/codejsha/algorithm-examples/actions/workflows/gradle.yml/badge.svg)
5+
![C++ CMake Test](https://github.com/codejsha/algorithm-examples/actions/workflows/cmake.yml/badge.svg) ![Python Poetry Test](https://github.com/codejsha/algorithm-examples/actions/workflows/poetry.yml/badge.svg) ![Java Gradle Test](https://github.com/codejsha/algorithm-examples/actions/workflows/gradle.yml/badge.svg) ![Go Test](https://github.com/codejsha/algorithm-examples/actions/workflows/go.yml/badge.svg)
66

77
[English](README.md) | [Korean](README_ko-KR.md)
88

9-
이 리포지토리는 알고리즘, 데이터 구조, 문제 해결에 대한 구현 예제들로 구성되어 있습니다. 예제들은 C++, Python, Java로 작성되었으며, 각 언어는 다음과 같은 테스트 프레임워크를 사용합니다: [Google Test](https://google.github.io/googletest/)(C++), [pytest](https://docs.pytest.org/)(Python), [JUnit](https://junit.org/)(Java). 테스트를 실행하여 알고리즘 로직에 대한 메서드/함수를 수행합니다.
9+
이 리포지토리는 알고리즘, 데이터 구조, 문제 해결에 대한 구현 예제들로 구성되어 있다. 예제들은 C++, Python, Java, Go로 작성되었으며, 각 언어는 다음과 같은 테스트 프레임워크/패키지를 사용한다: [Google Test](https://google.github.io/googletest/)(C++), [pytest](https://docs.pytest.org/)(Python), [JUnit](https://junit.org/)(Java), [go test](https://pkg.go.dev/cmd/go)(Go). 테스트를 실행하여 알고리즘 로직에 대한 메서드/함수를 수행한다.
1010

1111
## Project Environments
1212

@@ -15,3 +15,4 @@
1515
- C++ project: C++20 / [CMake](https://cmake.org/) build / [GNU Scientific Library (GSL)](https://www.gnu.org/software/gsl/), [Google Test](https://google.github.io/googletest/), [Google Benchmark](https://github.com/google/benchmark), [fmt](https://github.com/fmtlib/fmt) packages / [vcpkg](https://github.com/microsoft/vcpkg) package manager
1616
- Python project: Python 3.11 / [Poetry](https://python-poetry.org/) build / [NumPy](https://numpy.org/), [SciPy](https://www.scipy.org/), [NetworkX](https://networkx.org/), [pytest](https://docs.pytest.org/), [pytest-benchmark](https://pytest-benchmark.readthedocs.io/en/latest/) packages
1717
- Java project: Java 21 / [Gradle](https://gradle.org/) build / [Guava](https://github.com/google/guava), [JUnit](https://junit.org/), [Java Microbenchmark Harness (JMH)](https://github.com/openjdk/jmh) libraries
18+
- Go project: Go 1.22 / Go build / [Testify](https://github.com/stretchr/testify) package

‎go-algorithm/.gitignore

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
### Go template
2+
# If you prefer the allow list template instead of the deny list, see community template:
3+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
4+
#
5+
# Binaries for programs and plugins
6+
*.exe
7+
*.exe~
8+
*.dll
9+
*.so
10+
*.dylib
11+
12+
# Test binary, built with `go test -c`
13+
*.test
14+
15+
# Output of the go coverage tool, specifically when used with LiteIDE
16+
*.out
17+
18+
# Dependency directories (remove the comment below to include it)
19+
# vendor/
20+
21+
# Go workspace file
22+
go.work
23+
24+
### VisualStudioCode template
25+
.vscode/*
26+
!.vscode/settings.json
27+
!.vscode/tasks.json
28+
!.vscode/launch.json
29+
!.vscode/extensions.json
30+
!.vscode/*.code-snippets
31+
32+
# Local History for Visual Studio Code
33+
.history/
34+
35+
# Built Visual Studio Code Extensions
36+
*.vsix
37+
38+
### JetBrains template
39+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
40+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
41+
42+
# User-specific stuff
43+
.idea/**/workspace.xml
44+
.idea/**/tasks.xml
45+
.idea/**/usage.statistics.xml
46+
.idea/**/dictionaries
47+
.idea/**/shelf
48+
49+
# AWS User-specific
50+
.idea/**/aws.xml
51+
52+
# Generated files
53+
.idea/**/contentModel.xml
54+
55+
# Sensitive or high-churn files
56+
.idea/**/dataSources/
57+
.idea/**/dataSources.ids
58+
.idea/**/dataSources.local.xml
59+
.idea/**/sqlDataSources.xml
60+
.idea/**/dynamic.xml
61+
.idea/**/uiDesigner.xml
62+
.idea/**/dbnavigator.xml
63+
64+
# Gradle
65+
.idea/**/gradle.xml
66+
.idea/**/libraries
67+
68+
# Gradle and Maven with auto-import
69+
# When using Gradle or Maven with auto-import, you should exclude module files,
70+
# since they will be recreated, and may cause churn. Uncomment if using
71+
# auto-import.
72+
# .idea/artifacts
73+
# .idea/compiler.xml
74+
# .idea/jarRepositories.xml
75+
# .idea/modules.xml
76+
# .idea/*.iml
77+
# .idea/modules
78+
# *.iml
79+
# *.ipr
80+
81+
# CMake
82+
cmake-build-*/
83+
84+
# Mongo Explorer plugin
85+
.idea/**/mongoSettings.xml
86+
87+
# File-based project format
88+
*.iws
89+
90+
# IntelliJ
91+
out/
92+
93+
# mpeltonen/sbt-idea plugin
94+
.idea_modules/
95+
96+
# JIRA plugin
97+
atlassian-ide-plugin.xml
98+
99+
# Cursive Clojure plugin
100+
.idea/replstate.xml
101+
102+
# SonarLint plugin
103+
.idea/sonarlint/
104+
105+
# Crashlytics plugin (for Android Studio and IntelliJ)
106+
com_crashlytics_export_strings.xml
107+
crashlytics.properties
108+
crashlytics-build.properties
109+
fabric.properties
110+
111+
# Editor-based Rest Client
112+
.idea/httpRequests
113+
114+
# Android studio 3.1+ serialized cache file
115+
.idea/caches/build_file_checksums.ser
116+
117+
### Others
118+
.idea/
119+
.vscode/
120+
README_link.md

‎go-algorithm/go.mod

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module go-algorithm
2+
3+
go 1.22.4
4+
5+
require github.com/stretchr/testify v1.9.0
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

‎go-algorithm/go.sum

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

‎go-algorithm/internal/math/gcd.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package math
2+
3+
// GCD returns the greatest common divisor of a(dividend) and b(divisor).
4+
func GCD(a int, b int) int {
5+
for b != 0 {
6+
a, b = b, a%b
7+
}
8+
return a
9+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package math
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestGCD(t *testing.T) {
9+
assert.Equal(t, 12, GCD(24, 36))
10+
assert.Equal(t, 1, GCD(17, 22))
11+
assert.Equal(t, 20, GCD(120, 500))
12+
}

0 commit comments

Comments
 (0)
Please sign in to comment.