commit e250be74f095091efe5e06ddc9b787c0dd473917 Author: Muhammad Nauman Raza Date: Tue Nov 19 20:47:13 2024 +0000 solutions: 1-3 diff --git a/even_fibonacci_numbers.rs b/even_fibonacci_numbers.rs new file mode 100644 index 0000000..e13d183 --- /dev/null +++ b/even_fibonacci_numbers.rs @@ -0,0 +1,16 @@ +fn main() { + let mut sequence: Vec = vec![1, 2]; + 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); + sequence.push(last); + } + for i in sequence.clone() { + if i % 2 != 0 || i > 4000000 { + sequence.remove(sequence.iter().position(|x| *x == i).expect("Item not found")); + } + } + let sum: i32 = sequence.iter().sum(); + println!("{}", sum); +} diff --git a/largest_prime_factor.rs b/largest_prime_factor.rs new file mode 100644 index 0000000..a7040f8 --- /dev/null +++ b/largest_prime_factor.rs @@ -0,0 +1,18 @@ +fn main() { + let mut num: u64 = 600851475143; + let mut factors: Vec = vec![]; + let mut i: u64 = 2; + while i.pow(2) <= num { + if num % i == 0 { + factors.push(i); + num = (num as f64 / i as f64).floor() as u64; + } else { + i += 1; + } + } + if num != 1 { + factors.push(num); + } + + println!("{:?}", factors); +} diff --git a/multiples_of_3_or_5.rs b/multiples_of_3_or_5.rs new file mode 100644 index 0000000..ea317d6 --- /dev/null +++ b/multiples_of_3_or_5.rs @@ -0,0 +1,12 @@ +fn main() { + let mut multiples: Vec = vec![]; + for num in 0..1000 { + if num % 3 == 0 { + multiples.push(num); + } else if num % 5 == 0 { + multiples.push(num); + } + } + let sum: i32 = multiples.iter().sum(); + println!("{}", sum); +}