lc-go/create.sh

30 lines
698 B
Bash
Executable file

#!/bin/bash
id=$1
echo "$id" | grep -q "^[1-9][0-9]\{,4\}$" || {
echo "Err: no valid problem ID provided." >&2
exit 1
}
parent=$((id / 100))
pdir="solutions/${parent}/q${id}"
sol_file="${pdir}/solution.go"
if [ -f "$sol_file" ]; then
exit 0
fi
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$id implements solution for https://leetcode.com/problems/$title_slug/" > "$sol_file"
echo "package q$id" >> "$sol_file"
echo "Created $sol_file"