microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
minestarks/circuit-magic

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/npm/qsharp/src/katas.ts

93lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4import { default as katasContent } from "./katas-content.generated.js";
5
6export type Example = {
7 type: "example";
8 id: string;
9 code: string;
10};
11
12export type TextContent = {
13 type: "text-content";
14 content: string;
15};
16
17export type ContentItem = Example | TextContent;
18
19export type Solution = {
20 type: "solution";
21 id: string;
22 code: string;
23};
24
25export type ExplainedSolutionItem = ContentItem | Solution;
26
27export type ExplainedSolution = {
28 type: "explained-solution";
29 items: ExplainedSolutionItem[];
30};
31
32export type Exercise = {
33 type: "exercise";
34 id: string;
35 title: string;
36 description: TextContent;
37 sourceIds: string[];
38 placeholderCode: string;
39 explainedSolution: ExplainedSolution;
40};
41
42export type Answer = {
43 type: "answer";
44 items: ContentItem[];
45};
46
47export type Question = {
48 type: "question";
49 description: TextContent;
50 answer: Answer;
51};
52
53export type LessonItem = ContentItem | Question;
54
55export type Lesson = {
56 type: "lesson";
57 id: string;
58 title: string;
59 items: LessonItem[];
60};
61
62export type KataSection = Exercise | Lesson;
63
64export type Kata = {
65 id: string;
66 title: string;
67 sections: KataSection[];
68 published: boolean;
69};
70
71export async function getAllKatas(
72 options: { includeUnpublished?: boolean } = { includeUnpublished: false },
73): Promise<Kata[]> {
74 return katasContent.katas.filter(
75 (k) => options.includeUnpublished || k.published,
76 ) as Kata[];
77}
78
79export async function getKata(id: string): Promise<Kata> {
80 const katas = await getAllKatas({ includeUnpublished: true });
81 return (
82 katas.find((k) => k.id === id) ||
83 Promise.reject(`Failed to get kata with id: ${id}`)
84 );
85}
86
87export async function getExerciseSources(
88 exercise: Exercise,
89): Promise<string[]> {
90 return katasContent.globalCodeSources
91 .filter((source) => exercise.sourceIds.indexOf(source.id) > -1)
92 .map((source) => source.code);
93}
94