You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

994 B

partial_sums

Instructions

Write a partial_sums function that receives a reference of an array of u64 and returns a vector with the partial sums of the received array.

This is how partial sums work:

1- First you split the array in its partitions:

[1, 2, 3, 4, 5]
      |
      V
[1, 2, 3, 4, 5]
[1, 2, 3, 4]
[1, 2, 3]
[1, 2]
[1]
[]

2- Then you add each partition together:

[1, 2, 3, 4, 5] = 15
[1, 2, 3, 4]    = 10
[1, 2, 3]       = 6
[1, 2]          = 3
[1]             = 1
[]              = 0

3- So, in conclusion:

partial_sums(&[1, 2, 3, 4, 5]) // == [15, 10, 6, 3 ,1, 0]

Expected Result

pub fn matrix_determinant(arr: &[u64]) -> Vec<64>{

}

Example

Here is a program to test your function:

fn main() {
    println!(
        "Partial sums of [5, 18, 3, 23] is : {:?}",
        parts_sums(&[5, 18, 3, 23])
    );
}

And its output:

$ cargo run
Partial sums of [5, 18, 3, 23] is : [49, 26, 23, 5, 0]
$