Skip to content

Commit 35c3946

Browse files
Setup contentlayer for puzzles, update navbar
1 parent 83fa9f7 commit 35c3946

File tree

5 files changed

+255
-1
lines changed

5 files changed

+255
-1
lines changed

components/Navbar.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ export default function Navbar() {
5656
Creators
5757
</Text>
5858
</Link>
59+
<Link href="/puzzles">
60+
<Text
61+
as="a"
62+
size="label-lg"
63+
css={{
64+
color: '$slate12',
65+
cursor: 'pointer'
66+
}}>
67+
Puzzles
68+
</Text>
69+
</Link>
5970
<Text
6071
as="a"
6172
size="label-lg"

contentlayer.config.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,33 @@ export const Article = defineDocumentType(() => ({
6262
computedFields
6363
}))
6464

65+
export const Puzzle = defineDocumentType(() => ({
66+
name: 'Puzzle',
67+
filePathPattern: `puzzles/*.mdx`,
68+
contentType: 'mdx',
69+
fields: {
70+
title: {
71+
type: 'string',
72+
description: 'The title of the puzzle',
73+
required: true
74+
},
75+
desc: {
76+
type: 'string',
77+
description: 'One sentence that summarises the puzzle objective.',
78+
required: true
79+
},
80+
class: {
81+
type: 'string',
82+
description: 'The class the puzzle relates to',
83+
required: true
84+
}
85+
},
86+
computedFields
87+
}))
88+
6589
export default makeSource({
6690
contentDirPath: 'data',
67-
documentTypes: [Article],
91+
documentTypes: [Article, Puzzle],
6892
mdx: {
6993
remarkPlugins: [remarkGfm],
7094
rehypePlugins: [

data/puzzles/graph_detect_cycle.mdx

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: Graph Cycle Detection
3+
description: Given an undirected, unweighted graph with at least one edge, write a function that returns true if the graph contains a cycle, and false otherwise.
4+
class: COMP2521
5+
---
6+
7+
Given an undirected, unweighted graph with at least one edge, write a function that returns true if the graph contains a cycle, and false otherwise.
8+
9+
Implement the function `graphDetectCycle` in `graph_detect_cycle.c`. This function will then be called by the `main` function in `test_graph_detect_cycle.c`.
10+
11+
To run your solution:
12+
13+
```bash
14+
$ dcc test_graph_detect_cycle.c graph_detect_cycle.c Graph.c -o test_graph_detect_cycle
15+
$ ./test_graph_detect_cycle
16+
```
17+
18+
## Input format
19+
20+
The program will read from stdin.
21+
22+
The first line should be `n` the number of vertices in your graph.
23+
24+
The following lines (until EOF) contains the two vertices connected by an edge. Vertices are numbered `0` to `n-1` inclusive.
25+
26+
E.g `0 <-> 1` for an edge between vertices 0 and 1.
27+
28+
## Output format
29+
30+
The program will write to stdout.
31+
32+
It will print `Has cycle` if your `graphDetectCycle` function returns true, and `Does not have cycle` if it returns false.
33+
34+
## Sample 1
35+
36+
Input:
37+
38+
```bash
39+
3
40+
0 <-> 1
41+
1 <-> 2
42+
43+
```
44+
45+
Output:
46+
47+
```bash
48+
Does not have cycle
49+
```
50+
51+
Explanation: The graph `0 <-> 1 <-> 2` does not contain any cycles.
52+
53+
## Sample 2
54+
55+
Input:
56+
57+
```bash
58+
3
59+
0 <-> 1
60+
1 <-> 2
61+
0 <-> 2
62+
63+
```
64+
65+
Output:
66+
67+
```bash
68+
Has cycle
69+
```
70+
71+
Explanation: The graph contains a cycle for vertices 0, 1, 2.
72+
73+
## Sample 3
74+
75+
Input:
76+
77+
```bash
78+
6
79+
0 <-> 1
80+
1 <-> 2
81+
2 <-> 3
82+
2 <-> 4
83+
2 <-> 5
84+
85+
```
86+
87+
Output:
88+
89+
```bash
90+
Does not have cycle
91+
```
92+
93+
Explanation: The graph does not contain any cycles.
94+
95+
## Assumptions
96+
97+
- Graphs are undirected.
98+
- Graphs are unweighted.
99+
- Graphs are connected.
100+
- Graphs are not empty.
101+
- Graphs have no self-loops.
102+
- Graphs have no multiple edges.
103+
104+
## CSE Autotest
105+
106+
When you think your program is working, you can use CSE autotest to test your solution.
107+
108+
```bash
109+
$ 2521 autotest graph_detect_cycle
110+
```
111+
112+
## Solution
113+
114+
You can view the solution code to this problem [here](https://github.com/dqna64/comp2521-revision-session/blob/main/problems/graph_detect_cycle/solution/graph_detect_cycle.c).

pages/puzzles/[slug].tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import Avatar from 'boring-avatars'
2+
import { Flex } from 'components/Flex'
3+
import { Text } from 'components/Text'
4+
import { allPuzzles, Puzzle } from 'contentlayer/generated'
5+
import { format, parseISO } from 'date-fns'
6+
import { useMDXComponent } from 'next-contentlayer/hooks'
7+
import Head from 'next/head'
8+
import Image from 'next/image'
9+
import { Box } from 'components/Box'
10+
import Callout from 'components/Callout'
11+
import FileName from 'components/Filename'
12+
import Centerer from 'components/Centerer'
13+
import MultiChoice from 'components/MultiChoice'
14+
import Link from 'next/link'
15+
import { ArrowDown } from 'phosphor-react'
16+
17+
const defaultComponents = {
18+
Image,
19+
Callout,
20+
FileName,
21+
Centerer,
22+
MultiChoice,
23+
Link,
24+
ArrowDown
25+
}
26+
27+
// Add any components used in MDX files here.
28+
// Components here load dynamically if they're used.
29+
// See https://github.com/tsriram/with-mdx-bundler for details.
30+
const components = { ...defaultComponents }
31+
32+
export async function getStaticPaths() {
33+
const paths = allPuzzles.map((a) => ({ params: { slug: a.slug } }))
34+
return {
35+
paths,
36+
fallback: false
37+
}
38+
}
39+
40+
export async function getStaticProps({ params }: { params: Puzzle }) {
41+
const puzzle = allPuzzles.find((puzzle) => puzzle.slug === params.slug)
42+
return {
43+
props: {
44+
puzzle
45+
}
46+
}
47+
}
48+
49+
function ArticleHeader({ puzzle }: { puzzle: Puzzle }) {
50+
return (
51+
<Flex
52+
css={{
53+
flexDirection: 'column',
54+
padding: '0 0 1.4rem',
55+
borderBottom: 'solid 0.5px'
56+
}}>
57+
<Text
58+
size="headline"
59+
css={{ color: '$slate12', fontWeight: '600', paddingTop: '$2' }}>
60+
{puzzle.title}
61+
</Text>
62+
<Text size="title-sm" css={{ color: '$slate12', paddingTop: '$1' }}>
63+
{puzzle.desc}
64+
</Text>
65+
<Flex
66+
css={{
67+
flexDirection: 'row',
68+
gap: '0.75rem',
69+
alignItems: 'center',
70+
paddingTop: '$5'
71+
}}></Flex>
72+
</Flex>
73+
)
74+
}
75+
76+
const ArticleLayout = ({ puzzle }: { puzzle: Puzzle }) => {
77+
const MDXContent = useMDXComponent(puzzle.body.code)
78+
79+
return (
80+
<Flex css={{ justifyContent: 'center', paddingTop: '$6' }}>
81+
<Head>
82+
<title>{puzzle.title}</title>
83+
</Head>
84+
<Box css={{ paddingTop: '$2' }}>
85+
<Text>
86+
<MDXContent components={components} />
87+
</Text>
88+
</Box>
89+
</Flex>
90+
)
91+
}
92+
93+
export default ArticleLayout

pages/puzzles/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Card } from '@modulz/design-system'
2+
import { NextPage } from 'next'
3+
4+
const PuzzlesPage: NextPage = () => {
5+
return (
6+
<main>
7+
<Card>test</Card>
8+
</main>
9+
)
10+
}
11+
12+
export default PuzzlesPage

0 commit comments

Comments
 (0)