Skip to content

finished setting up page for 2521-fundamentals workshop #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions data/articles/break-continue-ternary.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: Break, Continue, and Ternary
date: 2023-09-27
desc: None of this code makes any sense to me! Help!
tags:
- 'COMP2521'
- 'Exam Revision'
author: CSESoc Education Team
coverPhoto: '/images/generic/alexandru-acea-XEB8y0nRRP4-unsplash.jpg'
---

# The break statement

Break statements work by telling your loop to immediately stop. It will not execute the remainder of the current iteration, and will just immediately jump to the end of the loop.

```c
while (1) {
if (1) {
break;
}
printf("this will not be printed!");
}
```

Oookay, but that sounds pretty useless... When would I ever want this!
Sometimes you want to check conditions before running an iteration, but it would become clunky top have it as a condition (think flag variables). In this case a `break` statement is great!

Consider the following clunky yucky code:

```c
int index = 0;
int found = 0;
while (index < SIZE && found = 0) {
if (array[index] == something) {
found = 1;
}
index++;
}
index--;
```

This can be simplified to:

```c
int index = 0;
while (index < SIZE) {
if (array[index] == something) {
break;
}
index++;
}
```

Nice, this makes things a lot tidier!
In general, I like to use break as a "catcher", whether it be to catch errors before they happen, or otherwise catch some condition to end my loop!

# The continue statement

Continue statements tell a loop to stop executing the rest of the code for that iteration, and jump straight back to the top!

```c
for (int i = 0; i < 20; ++i) {
if (i % 2 == 0) {
continue; // skip to the next iteration if the number is even
}
printf("%d\n", i); // will not print even numbers, since it will not get to this point
}
```

You might be thinking "this seems a lot more niche than `break`"...
And you're right! Usually `continue` just lets us avoid one layer of if-nesting, but if you spot a place where you want to go straight to the next iteration without ending the loop entirely, maybe this would be a option to consider!

In general, I don't use continue basically ever unless I get the lightbulb moment where the situation exactly matches one where I want to go straight to the next iteration.

# The ternary operator

This one is luckily quite simple, though daunting at first! Let's take a look at the general format of a ternary operator!

```c
variable = condition ? value_if_true : value_if_false;
```

This is exactly equivalent to:

```c
if (condition) {
variable = value_if_true;
} else {
variable = value_if_false;
}
```

Though note that a ternary doesn't necessary have to bind its value to a variable - you can just return it or otherwise use it if you want!

This is thankfully a pretty simple one - any time you want to set a value based on whether something is true or not, you can just use a ternary! **You should, however, think about whether it actually makes your code more readable.**
48 changes: 48 additions & 0 deletions data/workshops/2521-funda-23T3.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: CSESoc COMP2521 Fundamentals workshop
desc: Resources to give you a solid foundation for algorithms later in the course 😄
course: COMP2521 Fundamentals
offering: 23T3
---

# CSESoc COMP2521 Fundamentals workshop

This is a set of practical programming problems designed to help you develope a solid foundation for algorithms later in the course.

To start, log in to cse servers via ssh and create a new folder:

```bash:~
$ mkdir 2521-fundamentals
$ cd 2521-fundamentals
```

<br />

## Miscellaneous resources

<br />

### [Abstract Data Types - The Why and How]

[slides](https://docs.google.com/presentation/d/1wZ6S2RVDqLpSOQOlAyEl0lNuVgo39vG4VSE3BWUG0ww/edit?usp=sharing)

<figure class="video_container">
<iframe
src="https://docs.google.com/presentation/d/e/2PACX-1vQyClrhYOlgJ2duoeYd2eBVn21P4-lZ53pR10yWVk-Ou8XbtIeMpL2lKLAdZTIeikowLHdfrLSRoYs1/embed?start=false&loop=false&delayms=3000"
frameborder="0"
width="960"
height="569"
allowfullscreen="true"
mozallowfullscreen="true"
webkitallowfullscreen="true"></iframe>
</figure>

<br />

### [Time complexity analysis and Recursion]

<span> Recording </span>

### [How to use Break, Continue, and Ternary]

Access the article [here](/articles/break-continue-ternary)
83 changes: 83 additions & 0 deletions data/workshops/2521-funda-23T3/palindrome.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Palindrome
desc: Determine if a line is a palindrome or not **without using loops**.
class: COMP2521-funda
difficulty: 2
---

# Palindrome?

Create a new file called 'palindrome.c' and copy the starter code [here](https://github.com/Allynixtor/comp2521-fundamentals-23T3/blob/main/problems/palindrome/palindrome.c) into it.

An palindrome is a string which contains the same characters going forward and backwards.

Implement the `is_palindromic` function in `is_palindromic.c` to return true if a given input line is a palindrome, and false if it is not.
**But we have a problem, our computer is a tsundere and doesn't want you to use any loops at all!**

So, we must implement `is_palindromic` without any loops. Though you are free to make any extra functions you want (provided they also do not contain loops).

The output from your program should look **exactly** like this:

```bash:~/2521-fundamentals/palindrome
$ gcc is_palindromic.c -o is_palindromic
$ ./is_palindromic
Enter a line: racecar
The line is a palindrome!
```

```bash:~/2521-fundamentals/palindrome
$ ./is_palindromic
Enter a line:
The line is a palindrome!
```

```bash:~/2521-fundamentals/palindrome
$ ./is_palindromic
Enter a line: racecars
The line is not a palindrome!
```

```bash:~/2521-fundamentals/palindrome
$ ./is_palindromic
Enter a line: maam
The line is a palindrome!
```

```bash:~/2521-fundamentals/palindrome
$ ./is_palindromic
Enter a line: eeteee
The line is not a palindrome!
```

## Assumptions/Restrictions/Clarifications

- The main function handles replacing the newline with a null-terminator
- The input line string will be of length $N$ ($0 ≤ N ≤ 1024$)
- You are allowed to make other functions, but **must not use loops**.

## Hints

<details>
<summary> Hint 1 </summary>
<br />
if a string is a single character then it is always a palindrome, and you can
easily figure out if a two-character string is a palindrome with a single
comparison
</details>

<details>
<summary> Hint 2 </summary>
<br />
if a string is a palindrome, what can we say about the substring that excludes
the left-most and right-most letter?
</details>

<details>
<summary> Hint 3 </summary>
<br />
for a string to be a palindrome, the left-most and right-most letter must be
the same, and the substring excluding those two letters must be palindromic
</details>
## Solution

You can view the solution code to this problem [here](https://github.com/Allynixtor/comp2521-fundamentals-23T3/blob/main/problems/palindrome/solution.c).
85 changes: 85 additions & 0 deletions data/workshops/2521-funda-23T3/poggers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: Poggers
desc: Determine if a list is poggers or not **without using loops**.
class: COMP2521-funda
difficulty: 2
---

# Poggers?

Create a new file called 'poggers.c' and copy the starter code [here](https://github.com/Allynixtor/comp2521-fundamentals-23T3/blob/main/problems/poggers/poggers.c) into it.

An list is poggers if every node matches the following criteria:

- If the node is even, then the next node must be of strictly greater value.
- If the node is odd, then the next node must be of strictly lesser value.

Implement the `listIsPoggers` function in `listIsPoggers.c` to return true if the input list is poggers, and false otherwise.
**But we have a problem, our computer is a tsundere and doesn't want you to use any loops at all!**

So, we must implement `listIsPoggers` without any loops. Though you are free to make any extra functions you want (provided they also do not contain loops). For this exercise though, extra functions should not be necessary!

The output from your program should look **exactly** like this:

```bash:~/2521-fundamentals/poggers
$ gcc listIsPoggers.c -o listIsPoggers
$ ./listIsPoggers
Enter list size: 5
Enter list values: 3 2 3 2 3
List: [3, 2, 3, 2, 3]
POGGERS POGU POG
```

```bash:~/2521-fundamentals/poggers
$ ./listIsPoggers
Enter list size: 0
List: []
POGGERS POGU POG
```

```bash:~/2521-fundamentals/poggers
$ ./listIsPoggers
Enter list size: 5
Enter list values: 3 2 3 2 1
List: [3, 2, 3, 2, 1]
NOT POG
```

```bash:~/2521-fundamentals/poggers
$ ./listIsPoggers
Enter list size: 9
Enter list values: 2 4 8 9 3 -5 -6 -4 0
List: [2, 4, 8, 9, 3, -5, -6, -4, 0]
POGGERS POGU POG
```

## Assumptions/Restrictions/Clarifications

- You are allowed to make other functions, but **must not use any loops**.

## Hints

<details>
<summary> Hint 1 </summary>
<br />
We may trivially say that an empty list or a list with a singular node is
poggers.
</details>

<details>
<summary> Hint 2 </summary>
<br />
Assuming the sublist from list->next onwards is poggers, what can we say about
the requirement(s) for our list onwards to be poggers?
</details>

<details>
<summary> Hint 3 </summary>
<br />
If the sublist from list->next onwards is poggers, then we know that we only
need to check conditions between list->value and list->next->value.
</details>

## Solution

You can view the solution code to this problem [here](https://github.com/Allynixtor/comp2521-fundamentals-23T3/blob/main/problems/poggers/solution.c).
4 changes: 2 additions & 2 deletions pages/articles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const Articles: NextPage = ({ articles, allTags, courseOfferingContent, workshop

{/* Uncomment once we have content for workshops */}

{/* <Flex
<Flex
as="main"
css={{
flexDirection: 'column',
Expand All @@ -157,7 +157,7 @@ const Articles: NextPage = ({ articles, allTags, courseOfferingContent, workshop
Explore the many workshops our Education Team has curated to become big brain.
</Text>
<WorkshopsContainerHomePage allWorkshopsOffering={workshopOfferingContent} />
</Flex> */}
</Flex>

<Text
size="headline"
Expand Down
5 changes: 3 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Home: NextPage = ({ articles, courseOfferingContent, workshopOfferingConte
</Flex>
{/* Uncomment once we have content for workshops */}

{/* <Flex
<Flex
as="main"
css={{
flexDirection: 'column',
Expand All @@ -110,7 +110,8 @@ const Home: NextPage = ({ articles, courseOfferingContent, workshopOfferingConte
Explore the many workshops our Education Team has curated to become big brain.
</Text>
<WorkshopsContainerHomePage allWorkshopsOffering={workshopOfferingContent} />
</Flex> */}
</Flex>

<Flex
as="main"
css={{
Expand Down