2024-11-19 20:47:13 +00:00
|
|
|
fn main() {
|
|
|
|
let mut sequence: Vec<i32> = vec![1, 2];
|
2024-11-20 20:44:03 +00:00
|
|
|
while sequence[sequence.len() - 1] <= 4000000 {
|
|
|
|
let mut last = sequence[sequence.len() - 1];
|
|
|
|
let mut secondlast = sequence[sequence.len() - 2];
|
|
|
|
(secondlast, last) = (last, secondlast + last);
|
2024-11-19 20:47:13 +00:00
|
|
|
sequence.push(last);
|
|
|
|
}
|
|
|
|
for i in sequence.clone() {
|
|
|
|
if i % 2 != 0 || i > 4000000 {
|
2024-11-20 20:44:03 +00:00
|
|
|
sequence.remove(
|
|
|
|
sequence
|
|
|
|
.iter()
|
|
|
|
.position(|x| *x == i)
|
|
|
|
.expect("Item not found"),
|
|
|
|
);
|
2024-11-19 20:47:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let sum: i32 = sequence.iter().sum();
|
|
|
|
println!("{}", sum);
|
|
|
|
}
|