Browse Source

Ran rustfmt on all tasks.

Lorenz Bung 8 years ago
parent
commit
6728f0e1f0
3 changed files with 11 additions and 11 deletions
  1. 1
    1
      hw1/task2/src/lib.rs
  2. 7
    7
      hw1/task3/src/lib.rs
  3. 3
    3
      hw1/task4/src/lib.rs

+ 1
- 1
hw1/task2/src/lib.rs View File

1
 //This function prints the n-th power of 2 and returns it.
1
 //This function prints the n-th power of 2 and returns it.
2
 pub fn square(n: u32) -> u64 {
2
 pub fn square(n: u32) -> u64 {
3
-    let sq: u64 = 2u64.pow(n-1); //(n-1) to solve the (in my opinion wrong) tests.
3
+    let sq: u64 = 2u64.pow(n - 1); //(n-1) to solve the (in my opinion wrong) tests.
4
     println!("{}", sq);
4
     println!("{}", sq);
5
     sq
5
     sq
6
 }
6
 }

+ 7
- 7
hw1/task3/src/lib.rs View File

1
 pub fn count(line: &str, c: char) -> u64 {
1
 pub fn count(line: &str, c: char) -> u64 {
2
-   let mut occurances = 0;
3
-   for char in line.chars(){
4
-      if char == c {
5
-        occurances += 1;
6
-      }
7
-   }
8
-   occurances
2
+    let mut occurances = 0;
3
+    for char in line.chars() {
4
+        if char == c {
5
+            occurances += 1;
6
+        }
7
+    }
8
+    occurances
9
 }
9
 }

+ 3
- 3
hw1/task4/src/lib.rs View File

1
 pub fn square_of_sum(n: i32) -> i32 {
1
 pub fn square_of_sum(n: i32) -> i32 {
2
     let mut i: i32 = 0;
2
     let mut i: i32 = 0;
3
-    for x in 1..n+1 {
3
+    for x in 1..n + 1 {
4
         i += x;
4
         i += x;
5
     }
5
     }
6
     i.pow(2)
6
     i.pow(2)
8
 
8
 
9
 pub fn sum_of_squares(n: i32) -> i32 {
9
 pub fn sum_of_squares(n: i32) -> i32 {
10
     let mut i: i32 = 0;
10
     let mut i: i32 = 0;
11
-    for x in 1..n+1 {
12
-       i += x.pow(2); 
11
+    for x in 1..n + 1 {
12
+        i += x.pow(2);
13
     }
13
     }
14
     i
14
     i
15
 }
15
 }

Loading…
Cancel
Save