diff --git a/problems/valid-parentheses.ts b/problems/valid-parentheses.ts index fdfec91..73ad104 100644 --- a/problems/valid-parentheses.ts +++ b/problems/valid-parentheses.ts @@ -1,50 +1,36 @@ -type Tail = T extends [...infer _, infer Last] - ? Last - : never; +type Tail = + T extends [...infer _, infer Last] ? Last : never; -type Head = T extends [infer First, ...infer _] - ? First - : never; +type RemoveLast = + T extends [...infer Rest, infer _] ? Rest : never; -type RemoveLast = T extends [...infer Rest, infer _] - ? Rest +type InvertOpen = + T extends "(" ? ")" + : T extends "[" ? "]" + : T extends "{" ? "}" : never; -type InvertOpen = T extends "(" - ? ")" - : T extends "[" - ? "]" - : T extends "{" - ? "}" - : never; - -type ValidClose< - Current extends string, - Stack extends string[], -> = Current extends ")" | "}" | "]" - ? InvertOpen> extends Current - ? true +type ValidClose = + Current extends ")" | "}" | "]" ? + InvertOpen> extends Current ? + true : false : false; -type IsValidParentheses< - S extends string, - Stack extends string[] = [], -> = S extends `${infer F}${infer R}` - ? F extends "(" | "{" | "[" - ? IsValidParentheses - : ValidClose extends true - ? IsValidParentheses> - : false - : Stack["length"] extends 0 - ? true - : false; +type IsValidParentheses = + S extends `${infer F}${infer R}` ? + F extends "(" | "{" | "[" ? IsValidParentheses + : ValidClose extends true ? + IsValidParentheses> + : false + : Stack["length"] extends 0 ? true + : false; -type Result1 = IsValidParentheses<"()">; +export type Result1 = IsValidParentheses<"()">; // ^? -type Result2 = IsValidParentheses<"()[]{}">; +export type Result2 = IsValidParentheses<"()[]{}">; // ^? -type Result3 = IsValidParentheses<"(]">; +export type Result3 = IsValidParentheses<"(]">; // ^? diff --git a/src/components/ProblemView.astro b/src/components/ProblemView.astro index 982f7f1..da720fc 100644 --- a/src/components/ProblemView.astro +++ b/src/components/ProblemView.astro @@ -15,8 +15,10 @@ const { name } = Astro.props; const fileText = await readFile(`${process.cwd()}/problems/${name}.ts`); const tsCode = fileText.toString(); - -const html = await codeToHtml(tsCode, { +const cleanCode = tsCode + .replaceAll("export type", "type") + .replaceAll("// ^?", "// ^?"); +const html = await codeToHtml(cleanCode, { lang: "ts", theme: "vitesse-dark", transformers: [