-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_missing_notes.sh
More file actions
executable file
·173 lines (149 loc) · 6.36 KB
/
create_missing_notes.sh
File metadata and controls
executable file
·173 lines (149 loc) · 6.36 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# LeetCode Notes Generator
# This script automatically creates missing note files for solved problems
NOTES_DIR="src/notes"
EXERCISES_DIR="src/exercises"
# Create notes directory if it doesn't exist
mkdir -p "$NOTES_DIR"
echo "🧠 Scanning exercises directory and generating missing LeetCode problem notes..."
# Function to convert problem number to 3-digit format
format_problem_number() {
local num=$1
printf "%03d" $num
}
# Function to convert title to filename format
title_to_filename() {
echo "$1" | tr ' ' '_' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]//g'
}
# Function to extract problem number from filename
extract_problem_number() {
local filename=$1
echo "$filename" | sed 's/^\([0-9]*\)\..*/\1/'
}
# Function to convert filename to problem title
filename_to_title() {
local filename=$1
# Remove the .py extension and problem number
local title=$(echo "$filename" | sed 's/^[0-9]*\.//' | sed 's/\.py$//')
# Convert kebab-case to Title Case with proper handling
echo "$title" | sed 's/-/ /g' | sed 's/\b\w/\U&/g' | sed 's/\bii\b/II/g' | sed 's/\biii\b/III/g'
}
# Function to get difficulty color for shields
get_difficulty_color() {
local difficulty=$1
case $difficulty in
"Easy")
echo "brightgreen"
;;
"Medium")
echo "orange"
;;
"Hard")
echo "red"
;;
*)
echo "blue"
;;
esac
}
# Function to determine difficulty dynamically (default to Medium for unknown problems)
get_difficulty() {
local problem_num=$1
# For now, default to Medium for all problems
# This can be enhanced later with API calls or a separate difficulty mapping file
echo "Medium"
}
# Function to create note file
create_note_file() {
local problem_num=$1
local title=$2
local difficulty=$3
local filename="$NOTES_DIR/$(format_problem_number $problem_num)_$(title_to_filename "$title").md"
if [ ! -f "$filename" ]; then
local difficulty_color=$(get_difficulty_color "$difficulty")
local leetcode_url="https://leetcode.com/problems/$(echo "$title" | tr ' ' '-')/"
echo "# $title" > "$filename"
echo "" >> "$filename"
echo "[](https://leetcode.com/problems/$(echo "$title" | tr ' ' '-')/)" >> "$filename"
echo "[](https://leetcode.com/problemset/?difficulty=$(echo "$difficulty" | tr '[:lower:]' '[:upper:]'))" >> "$filename"
echo "[]($leetcode_url)" >> "$filename"
echo "" >> "$filename"
echo "**Problem Number:** [$problem_num]($leetcode_url)" >> "$filename"
echo "**Difficulty:** [$difficulty](https://leetcode.com/problemset/?difficulty=$(echo "$difficulty" | tr '[:lower:]' '[:upper:]'))" >> "$filename"
echo "**Category:** " >> "$filename"
echo "**LeetCode Link:** [$leetcode_url]($leetcode_url)" >> "$filename"
echo "" >> "$filename"
echo "## Problem Description" >> "$filename"
echo "" >> "$filename"
echo "> **View the full problem description on LeetCode:** [$title]($leetcode_url)" >> "$filename"
echo "" >> "$filename"
echo "## My Approach" >> "$filename"
echo "" >> "$filename"
echo "## Solution" >> "$filename"
echo "" >> "$filename"
echo "## Time & Space Complexity" >> "$filename"
echo "" >> "$filename"
echo "## Key Insights" >> "$filename"
echo "" >> "$filename"
echo "## Mistakes Made" >> "$filename"
echo "" >> "$filename"
echo "## Related Problems" >> "$filename"
echo "" >> "$filename"
echo "---" >> "$filename"
echo "" >> "$filename"
echo "[](../../README.md#-problem-index) | [.py)](../exercises/$problem_num.$(echo "$title" | tr ' ' '-').py)" >> "$filename"
echo "" >> "$filename"
echo "*Note: This is a work in progress. I'll add more details as I reflect on this problem.*" >> "$filename"
echo "✅ Created: $filename"
return 0
else
echo "⏭️ Skipped: $filename (already exists)"
return 1
fi
}
# Counter for statistics
created_count=0
skipped_count=0
# Scan exercises directory for Python files
if [ -d "$EXERCISES_DIR" ]; then
for file in "$EXERCISES_DIR"/*.py; do
if [ -f "$file" ]; then
# Extract filename without path
filename=$(basename "$file")
# Skip empty files
if [ ! -s "$file" ]; then
echo "⚠️ Skipped empty file: $filename"
continue
fi
# Extract problem number
problem_num=$(extract_problem_number "$filename")
# Skip if no problem number found
if [ -z "$problem_num" ] || [ "$problem_num" = "$filename" ]; then
echo "⚠️ Skipped invalid filename: $filename"
continue
fi
# Convert filename to title
title=$(filename_to_title "$filename")
# Get difficulty (default to Medium for now)
difficulty=$(get_difficulty "$problem_num")
# Create note file
if create_note_file "$problem_num" "$title" "$difficulty"; then
((created_count++))
else
((skipped_count++))
fi
fi
done
else
echo "❌ Error: Exercises directory '$EXERCISES_DIR' not found!"
exit 1
fi
echo ""
echo "🎉 Note generation complete!"
echo "📝 Files processed: $((created_count + skipped_count))"
echo "✅ New notes created: $created_count"
echo "⏭️ Notes skipped (already exist): $skipped_count"
echo "📁 Notes directory: $NOTES_DIR"
echo ""
echo "💡 Tip: Run this script whenever you solve new problems to automatically create note templates."
echo "🔧 Note: All problems default to 'Medium' difficulty. You can manually update difficulties in the notes."