#!/usr/bin/env python
import random
import sys
from pathlib import Path
from rich.console import Console
LC_COUNT = 2218
TIME_LIMITS = {
"Hard": "20:00",
"Medium": "12:30",
"Easy": "7:30",
}
crushed = {}
mediocre = {}
attempted = {}
short_list = {
# Blind 75
76,
102,
105,
124,
128,
143,
152,
153,
198,
207,
208,
211,
212,
213,
230,
238,
252,
269,
271,
295,
300,
322,
323,
371,
417,
422,
424,
435,
449,
1143,
}
all_lc = {num for num in range(1, LC_COUNT + 1)}
untried = all_lc.difference(crushed)
lc_options = short_list or attempted or untried or mediocre
lc_options = lc_options.difference(crushed)
if len(sys.argv) > 1:
num = sys.argv[1]
else:
num = random.choice(list(lc_options))
console = Console()
def user_input() -> str:
return console.input(prompt="[bold blue]>>>[/bold blue] ")
console.print("LC:", num)
base_path = Path.home() / "LC/"
for existing_path in base_path.glob(f"*/{num}-*.md"):
console.print("File already exists:", existing_path)
exit()
difficulty = ""
while difficulty not in TIME_LIMITS:
console.print(f"Difficulty {list(TIME_LIMITS.keys())}:")
difficulty = user_input().strip().capitalize()
name = ""
while not name:
console.print("Name:")
name = user_input().strip().replace(" ", " ")
url_name = name.lower().replace(" ", "-")
path = base_path / f"{difficulty}/{num}-{url_name}.md"
template = f"""# Problem: {name.title()}
https://leetcode.com/problems/{url_name}/
*Difficulty:* {difficulty}
*Status:* Untried
*Time:* ? left out of {TIME_LIMITS[difficulty]} minutes
# Notes:
# Attempts:
##
Time: O(?)
Space: O(?)
```
```
# Solutions:
##
Time: O(?)
Space: O(?)
"""
if path.exists():
console.print("File already exists:", path)
else:
console.print("Creating file:", path)
with open(path, "w") as outfile:
outfile.write(template)
console.print("Done", style="bold green")
I have had keys give out 2 times in as many years, but both times the RMA process was quite smooth.