use .sum() on an iterator
parent
dd3d4a7929
commit
21d0ccd59a
|
@ -3,10 +3,7 @@ use std::io::{BufRead, BufReader};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
fn print_final_frequency(ints: &Vec<i32>) {
|
fn print_final_frequency(ints: &Vec<i32>) {
|
||||||
let mut frequency = 0;
|
let frequency: i32 = ints.iter().sum();
|
||||||
for drift in ints {
|
|
||||||
frequency = frequency + drift;
|
|
||||||
}
|
|
||||||
println!("frequency is {}", frequency)
|
println!("frequency is {}", frequency)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue