Merge branch 'main' into 'main'

Sync between public and private

See merge request kaist-cp-class/cs220-private!32
This commit is contained in:
Haechan An
2023-09-12 08:23:02 +00:00
30 changed files with 275 additions and 42 deletions

View File

@@ -0,0 +1,82 @@
name: Question about Assignment
description: Ask questions about assignment in this format.
title: '[Assignment #] (SUMMARIZE YOUR QUESTION AS CLEARLY AS POSSIBLE)'
labels:
- question
assignees:
- woojinnn
- jirheee
- AnHaechan
body:
- type: markdown
attributes:
value: |
# Please read the followings before asking a question:
- When you're asking a question, please make sure,
- You clarify your questions as clear as possible.
- If possible, please make it a yes/no question.
- If possible, please summarize your question in one sentence at the beginning of an issue.
- If you're asking a question on concepts,
- You read the corresponding sections of the slide.
- You searched for the concepts using search engines and Wikipedia.
- If you're asking a question on Rust programming,
- You searched for error messages or any relevant logs using search engines.
- Your problem is reproducible in the provided server. Please describe how others can reproduce your problem.
- You paste code, if any, in text with [syntax hightlight](https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks). No images.
- You paste code, if any, that is minimized as much as possible. Your code should be immediately relevant to your question.
- type: markdown
attributes:
value: |
# 1. Related Issue
- type: input
attributes:
label: Related Issue
description: >-
Please search to see if a related issue already exists. If so, give me
the links. If there are multiple issues, please write them all.
placeholder: 'https://github.com/kaist-cp/cs220/issues/<issue_number>'
validations:
required: false
- type: markdown
attributes:
value: |
# 2. Googling Result
- type: textarea
attributes:
label: Googling Result
description: >-
Share the link that looks relavant to your situation. Multiple links are
welcomed.
placeholder: >-
https://stackoverflow.blog/2020/01/20/what-is-rust-and-why-is-it-so-popular/
validations:
required: true
- type: markdown
attributes:
value: |
# 3. ChatGPT Result
- type: input
attributes:
label: ChatGPT Result
description: >-
Before writing this issue, you should have asked ChatGPT. We want to see
how you used ChatGPT for troubleshooting your problem. You can upload
link like
[this](https://help.openai.com/en/articles/7925741-chatgpt-shared-links-faq).
It should contain the history of, including but not limited to, your
problem statement, the answer from ChatGPT, and your follow-up
questions. There should be at least 3 turns of conversation.
placeholder: 'https://chat.openai.com/share/<conversation-ID>'
validations:
required: true
- type: markdown
attributes:
value: |
# 4. Your question
- type: textarea
attributes:
label: Your question here
description: 'Also tell us, what did you expect to happen?'
placeholder: YOUR QUESTION HERE
validations:
required: true

View File

@@ -138,7 +138,22 @@ Make sure that you're capable of using the following development tools:
- We'll announce **all** assignments before the semester begins.
- Submit your solution to <https://gg.kaist.ac.kr/course/17>.
- **How to submit your assignment:**
- To submit your solution, you should run `submit.sh` in `scripts` directory. In other words, you should run the following command:
```bash
# Run this command at the root directory of this repository.
$ ./scripts/submit.sh
```
- After running the command above, in the `target` directory, you can find a `assignment<NUMBER>.zip` file (`assignment09.zip` for example). Submit this file to <https://gg.kaist.ac.kr/course/17>.
- Read the documentation at <https://cp.kaist.ac.kr/cs220/cs220/>.
- You can check your grade of each assignment by running the grading script.
- You can run the grading script with the following command:
```bash
$ ./scripts/grade.sh <assignment_number>
# E.g. To grade `assignment09`, run the following command:
$ ./scripts/grade.sh 9
```
- You're **allowed** to use ChatGPT or other LLMs. Instead, you'll solve more problems than previous semesters.
@@ -150,8 +165,11 @@ Make sure that you're capable of using the following development tools:
- Your physical apperance is required. If online participation is **absolutely necessary**, we'll use Zoom.
- You'll bring your own laptop. (You can also borrow one from School of Computing Admin Team.)
We will use surveillance tools such as [Safe Exam Browser](https://safeexambrowser.org/) to monitor your laptop.
- You should bring your own laptop. (You can also borrow one from School of Computing Admin Team.)
- We will use [Safe Exam Browser](https://safeexambrowser.org/) to prevent cheatings.
- You should have your laptop configured with Safe Exam Browser before the exam.
- TBA: Details will be announced later.
### Attendance (?%)
@@ -184,8 +202,7 @@ Make sure that you're capable of using the following development tools:
- Ask questions on course materials and assignments in [this repository's issue tracker](https://github.com/kaist-cp/cs220/issues).
+ Don't send emails to the instructor or TAs for course materials and assignments.
+ Before asking a question, consult with the issue tracker, Google, Stack Overflow, and LLMs.
+ When creating a new issue, you are going to be asked to fill out a template. Make sure that you fill out the template properly.
+ Before asking a question, ask it to [ChatGPT](https://chat.openai.com/). Or search for it in Google and Stack Overflow.
+ Describe your question in as much detail as possible. It should include the following things:
* Environment (OS, gcc, g++ version, and any other related program information).
* Command(s) that you used and the result. Any logs should be formatted in code. Refer to [this](https://guides.github.com/features/mastering-markdown/).
@@ -193,6 +210,7 @@ Make sure that you're capable of using the following development tools:
* Googling result. Search before asking, and share the keyword used for searching and what you've learned from it.
+ Give a proper title to your issue.
+ Read [this](https://github.com/kaist-cp/cs220#communication) for more instructions.
+ Questions will be answered within 2 days mostly.
+ I'm requiring you to ask questions online first for two reasons. First, clearly writing a
question is the first step to reaching an answer. Second, you can benefit from the questions and answers of other students.

View File

@@ -0,0 +1,17 @@
# Assignment 5: Program correctness and logic
* The primary goal of this assignment is to grasp basic concepts about proving a program's correctness with deductive reasoning.
* You should fill in `TODO`s in three files: `max.mlw`, `binary_search.mlw`, `pascal.mlw`.
* You will get PARTIAL SCOREs for each of those three files.
* E.g. If `max.mlw` and `binary_search.mlw` get passed, 2 out of 3 points will be given.
* You may use [Why3 in your browser](https://why3.lri.fr/try/).
* Clicking `Verify` button at the top will open a panel on the right side.
* For each task in the panel (e.g. `loop invariant preservation`), you can right-click it and run the prover.
* Fill in `TODO`s until the prover can verify all tasks, notified with green check-marks.
* To submit your solution, run `./scripts/submit.sh` and submit `assignment05.zip` in the `target` directory to gg.
* More on Why3: <https://why3.lri.fr/doc/index.html>
* Why3 standard library: <https://why3.lri.fr/stdlib/index.html>

View File

@@ -20,4 +20,4 @@ module BinarySearch
(* IMPORTANT: DON'T MODIFY THE ABOVE LINES *)
0 (* TODO *)
end
end

View File

@@ -1,9 +1,14 @@
(* Max
Given an array `a` of natural numbers with length `n`,
return the maximum element of the array.
Given an array `a` of integers with length `n` greater than `0`,
return `max_idx`, the index of the maximum element of that array.
You should stengthen the loop invariant.
E.g. `max_idx [5, 12, 34, 10] 4` will return `2`
E.g. `max_idx [4, 3, 2] 3` will return `0`
E.g. `max_idx [1, 2, 3, 4] 4` will return `3`
Prove the below program indeed follows the given specification,
by giving an appropriate invariant.
*)
module Max
@@ -12,18 +17,21 @@ module Max
use ref.Ref
use array.Array
let max (a: array int) (n: int) : (max: int)
let max_idx (a: array int) (n: int) : (max_idx: int)
requires { length a > 0 }
requires { n = length a }
requires { forall i. 0 <= i < n -> a[i] >= 0 }
ensures { forall i. 0 <= i < n -> a[i] <= max }
ensures { exists i. 0 <= i < n -> a[i] = max }
= let ref max = 0 in
for i = 0 to n - 1 do
ensures { 0 <= max_idx <= n-1 }
ensures { forall i. 0 <= i <= n-1 -> a[i] <= a[max_idx] }
=
let ref max_idx = 0 in
for i = 0 to n-1 do
invariant { 0 <= max_idx <= n-1 }
(* IMPORTANT: DON'T MODIFY THE ABOVE LINES *)
invariant { true (* TODO: Replace `true` with your solution *) }
invariant { true (* TODO: Replace `true` with your solution. Your solution MUST be a single line, at line number 30. DON'T add another line of codes. *) }
(* IMPORTANT: DON'T MODIFY THE BELOW LINES *)
if max < a[i] then max <- a[i];
if a[max_idx] < a[i] then max_idx <- i;
done;
max
max_idx
end
end

View File

@@ -10,13 +10,15 @@ module Pascal
use ref.Ref
use array.Array
(* The mathematical combination, defined recursively. *)
let rec function comb (n k: int) : int
requires { 0 <= k <= n }
variant { n }
ensures { result >= 1 }
= if k = 0 || k = n then 1 else comb (n-1) k + comb (n-1) (k-1)
(* Insert appropriate invariants so that Why3 can verify this function. *)
(* Computes the Pascal's triangle and returns the `n`th row of it. *)
(* Insert an appropriate invariant so that Why3 can verify this function. *)
(* You SHOULD understand the Pascal's triangle first to find good invariants. *)
let chooses (n : int) : array int
requires { n > 0 }
@@ -30,7 +32,7 @@ module Pascal
let new_row = Array.make (r+1) 1 in
for c = 1 to r-1 do
(* IMPORTANT: DON'T MODIFY THE ABOVE LINES *)
invariant { true (* TODO: Replace `true` with your solution *) }
invariant { true (* TODO: Replace `true` with your solution. Your solution MUST be a single line, at line number 35. DON'T add another lines. *) }
(* IMPORTANT: DON'T MODIFY THE BELOW LINES *)
new_row[c] <- row[c-1] + row[c]
done;
@@ -38,4 +40,4 @@ module Pascal
done;
row
end
end

View File

@@ -26,4 +26,4 @@ module Division
done;
q
end
end

View File

@@ -46,4 +46,4 @@ module FactLoop
done;
r
end
end

View File

@@ -48,4 +48,4 @@ module TwoWaySort
end
done
end
end

View File

@@ -27,4 +27,4 @@ module Division
done;
q
end
end

View File

@@ -34,4 +34,4 @@ module FactLoop
done;
r
end
end

View File

@@ -46,4 +46,4 @@ module TwoWaySort
end
done
end
end

View File

@@ -16,6 +16,14 @@ run_linters || exit 1
# Executes test for each runner.
echo "Running with $RUNNER..."
if [ $# != 1 ]
then
echo "==============================="
echo "Invalid argument."
echo "Usage: './grade.sh <assignment_number>'"
echo "Example: './grade.sh 1' to grade assignment01"
exit 1
fi
TEST_NAME=$(printf "TEST%02d" $1)
case $TEST_NAME in
TEST01)
@@ -95,11 +103,13 @@ case $TEST_NAME in
)
;;
*)
echo_err "Invalid test name: $TEST_NAME"
echo_err "Invalid assignment number: $1"
echo_err "Assignment number should be within 1 to 12."
exit 1
;;
esac
# Runs tests.
SCORE=$(run_tests)
echo Your score: $SCORE
NUM_TESTS=${#TESTS[@]}
echo Your score: ${SCORE}/${NUM_TESTS}

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env bash
set -e
BASEDIR=$(dirname "$0")/..
mkdir -p $BASEDIR/target
zip -rj $BASEDIR/target/assignment04.zip src/assignments/assignment04
zip -rj $BASEDIR/target/assignment11.zip src/assignments/assignment11

22
scripts/submit.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
BASEDIR=$(dirname "$0")/..
mkdir -p $BASEDIR/target
for i in {01..13} ; do
if [ $i -eq 5 ]
then
if [ -f $BASEDIR/target/assignment05.zip ]; then
rm $BASEDIR/target/assignment05.zip
fi
zip -rj $BASEDIR/target/assignment05.zip $BASEDIR/assets/why3/assignment05
continue
fi
if [ -f $BASEDIR/target/assignment$i.zip ]; then
rm $BASEDIR/target/assignment$i.zip
fi
zip -rj $BASEDIR/target/assignment$i.zip $BASEDIR/src/assignments/assignment$i
done

View File

@@ -5,6 +5,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 1` works fine.
//! See `assigment01/small_exercises_grade.rs` and `/scripts/grade.sh 1` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment01.zip` file in `target` directory.
pub mod small_exercises;
mod small_exercises_grade;

View File

@@ -5,6 +5,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 2` works fine.
//! See `assigment02/*_grade.rs` and `/scripts/grade.sh 2` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment02.zip` file in `target` directory.
pub mod small_exercises;
mod small_exercises_grade;

View File

@@ -2,6 +2,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 3` works fine.
//! See `assignment03/*_grade.rs` and `/scripts/grade.sh 3` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment03.zip` file in `target` directory.
pub mod small_exercises;
mod small_exercises_grade;

View File

@@ -14,6 +14,13 @@
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 4` works fine.
//! See `assignment04/grade.rs` and `/scripts/grade.sh 4` for the test script.
//! Run `/scripts/prepare-submissions.sh` and submit `/target/assignment04.zip` to <https://gg.kaist.ac.kr>.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment04.zip` file in `target` directory.
pub mod context;
mod grade;

View File

@@ -4,6 +4,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 6` works fine.
//! See `assignment06/*_grade.rs` and `/scripts/grade.sh 6` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment06.zip` file in `target` directory.
pub mod semiring;
pub mod symbolic_differentiation;

View File

@@ -6,7 +6,7 @@ use std::ops::*;
/// Rational number represented by two isize, numerator and denominator.
///
/// Each Rational number should be normalized so that `demoninator` is nonnegative and `numerator` and `demoninator` are coprime.
/// See [`normalize`] for examples. As a corner case, 0 is represented by Rational { numerator: 0, demoninator: 0 }.
/// See `normalize` for examples. As a corner case, 0 is represented by Rational { numerator: 0, demoninator: 0 }.
///
/// For "natural use", Rational also overloads standard arithmetic operations, i.e, `+`, `-`, `*`, `/`.
///

View File

@@ -4,6 +4,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 7` works fine.
//! See `assignment07/*_grade.rs` and `/scripts/grade.sh 7` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment07.zip` file in `target` directory.
pub mod generator;
pub mod my_itertools;

View File

@@ -4,6 +4,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 8` works fine.
//! See `assignment08/*_grade.rs` and `/scripts/grade.sh 8` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment08.zip` file in `target` directory.
pub mod church;
pub mod small_exercises;

View File

@@ -11,7 +11,7 @@ use std::{iter::zip, ops::*};
/// For example, the vector `vec![44,345,3]` represents the integer
/// `44 * (2^32)^2 + 345 * (2^32) + 3`,
/// and the vector `vec![u32::MAX - 5, u32::MAX - 7]` represents the integer
/// `- (5 * 2^32 + 8)
/// `- (5 * 2^32 + 8)`
///
/// You will implement the `Add` and `Sub` trait for this type.
///

View File

@@ -4,6 +4,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 9` works fine.
//! See `assignment09/*_grade.rs` and `/scripts/grade.sh 9` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment09.zip` file in `target` directory.
pub mod bigint;
pub mod matmul;

View File

@@ -3,6 +3,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 10` works fine.
//! See `assignment10/*_grade.rs` and `/scripts/grade.sh 10` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment10.zip` file in `target` directory.
pub mod labyrinth;
pub mod small_exercises;

View File

@@ -90,7 +90,7 @@ impl SubGraph {
}
/// Returns true iff the subgraph contains a cycle. Nodes that do not belong to this subgraph
/// are ignored. See https://en.wikipedia.org/wiki/Cycle_(graph_theory) for an algorithm.
/// are ignored. See <https://en.wikipedia.org/wiki/Cycle_(graph_theory)> for an algorithm.
pub fn detect_cycle(&self) -> bool {
todo!()
}

View File

@@ -3,6 +3,13 @@
//! You should fill out `todo!()` placeholders in such a way that `/scripts/grade.sh 11` works fine.
//! See `assignment11/*_grade.rs` and `/scripts/grade.sh 11` for the test script.
//! Run `/scripts/prepare-submissions.sh` and submit `/target/assignment11.zip` to <https://gg.kaist.ac.kr>.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment11.zip` file in `target` directory.
pub mod graph;
pub mod linked_list;

View File

@@ -4,6 +4,13 @@
//!
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 12` works fine.
//! See `assignment12/*_grade.rs` and `/scripts/grade.sh 12` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment12.zip` file in `target` directory.
pub mod card;
pub mod demux;

View File

@@ -5,6 +5,13 @@
//! Refer to your solution for assignment 09. You will implement the parallelized version of assignment 09.
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade.sh 13` works fine.
//! See `assignment13/small_exercises_grade.rs` and `/scripts/grade.sh 13` for the test script.
//!
//! To submit, run
//! ```bash
//! # At the cs220 home directory,
//! ./scripts/submit.sh
//! ```
//! and submit the generated `assignment13.zip` file in `target` directory.
pub mod small_exercises;
mod small_exercises_grade;