瀏覽代碼

INIT: task4

Michael Mächtel 8 年之前
父節點
當前提交
4bbecc5a31
共有 4 個文件被更改,包括 70 次插入0 次删除
  1. 6
    0
      files/hw1.txt
  2. 22
    0
      hw1/task4/README.md
  3. 11
    0
      hw1/task4/src/lib.rs
  4. 31
    0
      hw1/task4/tests/task4.rs

+ 6
- 0
files/hw1.txt 查看文件

@@ -21,3 +21,9 @@
21 21
 ./hw1/task3/Cargo.toml
22 22
 ./hw1/task3/src/lib.rs
23 23
 ./hw1/task3/tests/task3.rs
24
+
25
+
26
+./hw1/task4/Cargo.toml
27
+./hw1/task4/src/lib.rs
28
+./hw1/task4/tests/task4.rs
29
+

+ 22
- 0
hw1/task4/README.md 查看文件

@@ -0,0 +1,22 @@
1
+# Homework hw1 task 4
2
+
3
+## prepare your task
4
+
5
+Run `cargo init` in your `task4/` directory.
6
+
7
+## task
8
+
9
+Find the difference between the sum of the squares and the square of the sum of the first N natural numbers.
10
+
11
+The square of the sum of the first ten natural numbers is,
12
+
13
+    (1 + 2 + ... + 10)**2 = 55**2 = 3025
14
+
15
+The sum of the squares of the first ten natural numbers is,
16
+
17
+    1**2 + 2**2 + ... + 10**2 = 385
18
+
19
+Hence the difference between the square of the sum of the first
20
+ten natural numbers and the sum of the squares is 2640:
21
+
22
+    3025 - 385 = 2640

+ 11
- 0
hw1/task4/src/lib.rs 查看文件

@@ -0,0 +1,11 @@
1
+pub fn square_of_sum(n: i32) -> i32 {
2
+    unimplemented!();
3
+}
4
+
5
+pub fn sum_of_squares(n: i32) -> i32 {
6
+    unimplemented!();
7
+}
8
+
9
+pub fn difference(n: i32) -> i32 {
10
+    unimplemented!();
11
+}

+ 31
- 0
hw1/task4/tests/task4.rs 查看文件

@@ -0,0 +1,31 @@
1
+extern crate task4;
2
+
3
+#[test]
4
+fn test_square_of_sum_5() {
5
+    assert_eq!(225, task4::square_of_sum(5));
6
+}
7
+
8
+#[test]
9
+fn test_sum_of_squares_5() {
10
+    assert_eq!(55, task4::sum_of_squares(5));
11
+}
12
+
13
+#[test]
14
+fn test_difference_5() {
15
+    assert_eq!(170, task4::difference(5));
16
+}
17
+
18
+#[test]
19
+fn test_square_of_sum_100() {
20
+    assert_eq!(25502500, task4::square_of_sum(100));
21
+}
22
+
23
+#[test]
24
+fn test_sum_of_squares_100() {
25
+    assert_eq!(338350, task4::sum_of_squares(100));
26
+}
27
+
28
+#[test]
29
+fn test_difference_100() {
30
+    assert_eq!(25164150, task4::difference(100));
31
+}

Loading…
取消
儲存