Skip to content

Commit

Permalink
add problem counter (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
spring1843 committed Jul 13, 2023
1 parent 1467bba commit 2c282a8
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 23 deletions.
15 changes: 15 additions & 0 deletions .github/scripts/count-rehearsals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Counts the number of rehearsal files in each section
set -euo pipefail

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# shellcheck source=.github/scripts/sections.sh
source "${SCRIPT_DIR}/sections.sh"

ALL_TESTS=0
# shellcheck disable=SC2154
for section in "${sections[@]}"; do
SECTION_TESTS=$(find "${section}" -name "*_test.go" | wc -l)
ALL_TESTS=$((ALL_TESTS + SECTION_TESTS))
done
echo $ALL_TESTS
22 changes: 6 additions & 16 deletions .github/scripts/export-md.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
#!/usr/bin/env bash
# Exports the markdown files from the docs site
set -euo pipefail

# This script is used to export the markdown files from the docs site
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# shellcheck source=./.github/scripts/sections.sh
source "${SCRIPT_DIR}/sections.sh"

declare -a files=(
README.md
complexity.md
./array/README.md
./strings/README.md
./linkedlist/README.md
./stack/README.md
./queue/README.md
./hashtable/README.md
./tree/README.md
./heap/README.md
./recursion/README.md
./dnc//README.md
./bit//README.md
./backtracking/README.md
./graph/README.md
./greedy/README.md
./dp/README.md
)
files+=("${sections[@]/%//README.md}")

for file in "${files[@]}"; do
cat "$file"
Expand Down
22 changes: 22 additions & 0 deletions .github/scripts/sections.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail

declare -a sections=(
./array
./strings
./linkedlist
./stack
./queue
./hashtable
./tree
./heap
./recursion
./dnc
./bit
./backtracking
./graph
./greedy
./dp
)

export sections
11 changes: 6 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
locale: "US"
- uses: github/super-linter@v4
env:
DEFAULT_BRANCH: main
Expand All @@ -22,10 +26,7 @@ jobs:
YAML_CONFIG_FILE: .yamllint.yml
VALIDATE_GITLEAKS: false
LOG_LEVEL: WARN
- uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
locale: "US"
VALIDATE_SHELL_SHFMT: false
tests:
runs-on: ubuntu-latest
steps:
Expand All @@ -37,7 +38,7 @@ jobs:
~/.cache/go-build
~/go/pkg/
~/go/bin/
key: go-cache-${{ hashFiles('go.sum') }}
key: go-cache-${{ hashFiles('go.mod') }}
- run: go test -v -coverprofile=profile.cov ./...
- uses: shogo82148/actions-goveralls@v1
with:
Expand Down
3 changes: 2 additions & 1 deletion greedy/task_scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package greedy

import "sort"

// Event represents an event to be scheduled.
type Event struct {
Name string
StartTime int
EndTime int
}

// Solves the problem in O(n*Log n) time and O(1) space.
// ScheduleEvents Solves the problem in O(n*Log n) time and O(1) space.
func ScheduleEvents(events []Event) []Event {
sort.Slice(events, func(i, j int) bool {
return events[i].EndTime < events[j].EndTime
Expand Down
2 changes: 1 addition & 1 deletion heap/heap_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func HeapSort(list []int) []int {
return sorted
}

// Returns a new Min Heap.
// NewMinHeap Returns a new Min Heap.
func NewMinHeap() *MinHeap {
return &MinHeap{
Data: []*Vertex{},
Expand Down
1 change: 1 addition & 0 deletions queue/queue_using_circular_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type UsingCircularArray struct {

const emptyValue = 0

// ErrQueueAtMaxCapacity occurs when the queue is at max capacity.
var ErrQueueAtMaxCapacity = errors.New("queue is at max capacity")

// NewCircularQueue returns a fixed size circular queue.
Expand Down
1 change: 1 addition & 0 deletions stack/basic_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type evaluation struct {
stack []float64
}

// ErrImbalancedParentheses occurs when the expression has imbalanced parentheses.
var ErrImbalancedParentheses = errors.New("expression has imbalanced parentheses")

// BasicCalculator solves the problem in O(n) time and O(n) space.
Expand Down
1 change: 1 addition & 0 deletions strings/reverse_vowels.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var (
`i`: true,
`u`: true,
}
// ErrPopStack is returned when the stack is empty.
ErrPopStack = errors.New("can not Pop on an empty stack")
)

Expand Down

0 comments on commit 2c282a8

Please sign in to comment.