feat: query the problem set for title and url
This commit is contained in:
parent
079c2d5dd5
commit
7bdd2b5d01
3 changed files with 57 additions and 8 deletions
23
create.sh
23
create.sh
|
|
@ -1,21 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
num=$1
|
||||
id=$1
|
||||
|
||||
echo "$num" | grep -q "^[1-9][0-9]\{,4\}$" || {
|
||||
echo "Err: no valid number given" >&2
|
||||
echo "$id" | grep -q "^[1-9][0-9]\{,4\}$" || {
|
||||
echo "Err: no valid problem ID provided." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
parent=$((num / 100))
|
||||
pdir="solutions/${parent}/q${num}"
|
||||
parent=$((id / 100))
|
||||
pdir="solutions/${parent}/q${id}"
|
||||
|
||||
sol_file="${pdir}/solution.go"
|
||||
|
||||
if [ -f "$sol_file" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Creating template for question No. $num" >&2
|
||||
title_slug=$(jq -r "select(.id == $id) | .titleSlug" ./problemset.jsonl)
|
||||
[ -n "$title_slug" ] || {
|
||||
echo "Err: problem $id not found in the problem set." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo -e "Creating template for problem \033[32m${id}: $title_slug\033[0m" >&2
|
||||
mkdir -pv "$pdir"
|
||||
echo "package q$num" > "$sol_file"
|
||||
echo "// Package q$id implements solution for https://leetcode.com/problems/$title_slug/" > "$sol_file"
|
||||
echo "package q$id" >> "$sol_file"
|
||||
|
||||
echo "Created $sol_file"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue