From a49fd236ad7dc6f22cc1ee23dacbb7fc71c8a368 Mon Sep 17 00:00:00 2001 From: RichoKD Date: Tue, 12 Nov 2024 15:19:57 +0100 Subject: [PATCH 1/4] Feat: day 4 --- src/main.rs | 10 ++++++++++ src/week_two/day_four.rs | 28 ++++++++++++++++++++++++++++ src/week_two/mod.rs | 1 + 3 files changed, 39 insertions(+) create mode 100644 src/week_two/day_four.rs create mode 100644 src/week_two/mod.rs diff --git a/src/main.rs b/src/main.rs index 646b6f7..6c4451d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod week_one; +mod week_two; use crate::week_one::{ day_one, @@ -6,10 +7,19 @@ use crate::week_one::{ day_two, }; +use crate::week_two::day_four::{ + convert_f_to_c, + generate_fibonacci_num +}; + fn main() { day_one::main(); day_two::main(); println!("{}", factorial(12)); println!("{}", is_prime(17)); println!("{}", guessing_game()); + + println!("\nWeek 2 \n ============================================================ \n"); + println!("Convert_F_to_C: {}", convert_f_to_c(100.0)); + println!("Nth fibonacci digit: {}", generate_fibonacci_num(10)); } diff --git a/src/week_two/day_four.rs b/src/week_two/day_four.rs new file mode 100644 index 0000000..cbd104b --- /dev/null +++ b/src/week_two/day_four.rs @@ -0,0 +1,28 @@ +pub fn main() { + println!("{}", convert_f_to_c(100.0)); + + generate_fibonacci_num(10); +} + +pub fn convert_f_to_c(f: f32) -> f32 { + (f - 32.0) * 5.0 / 9.0 +} + +pub fn generate_fibonacci_num(n: u32) -> u32 { + if n == 0 { + return 0; + } else if n == 1 { + return 1; + } + + let mut a = 0; + let mut b = 1; + for _ in 2..=n { + let temp = a + b; + a = b; + b = temp; + // println!("{n}: {b}"); + } + + b +} diff --git a/src/week_two/mod.rs b/src/week_two/mod.rs new file mode 100644 index 0000000..50db8e2 --- /dev/null +++ b/src/week_two/mod.rs @@ -0,0 +1 @@ +pub mod day_four; \ No newline at end of file From e31972e67f18207f67336eab2d40a734c4ff761e Mon Sep 17 00:00:00 2001 From: RichoKD Date: Wed, 13 Nov 2024 09:35:43 +0100 Subject: [PATCH 2/4] Fix: Fib count --- src/week_two/day_four.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/week_two/day_four.rs b/src/week_two/day_four.rs index cbd104b..afec6b0 100644 --- a/src/week_two/day_four.rs +++ b/src/week_two/day_four.rs @@ -17,7 +17,7 @@ pub fn generate_fibonacci_num(n: u32) -> u32 { let mut a = 0; let mut b = 1; - for _ in 2..=n { + for _ in 2..n { let temp = a + b; a = b; b = temp; From 6372b2d5b1da75e7bdb845e8b98b5e98bfc5596c Mon Sep 17 00:00:00 2001 From: RichoKD Date: Wed, 13 Nov 2024 10:05:59 +0100 Subject: [PATCH 3/4] Fix: removed mod.rs --- src/{week_two/mod.rs => week_two.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{week_two/mod.rs => week_two.rs} (100%) diff --git a/src/week_two/mod.rs b/src/week_two.rs similarity index 100% rename from src/week_two/mod.rs rename to src/week_two.rs From ea6d2dd8f470b4da2d3c739ddb5d60cc549e7cd4 Mon Sep 17 00:00:00 2001 From: RichoKD Date: Wed, 13 Nov 2024 10:13:57 +0100 Subject: [PATCH 4/4] Fix: renamed crates --- src/main.rs | 5 +---- src/week_two.rs | 2 +- src/week_two/{day_four.rs => day_one.rs} | 0 3 files changed, 2 insertions(+), 5 deletions(-) rename src/week_two/{day_four.rs => day_one.rs} (100%) diff --git a/src/main.rs b/src/main.rs index 6c4451d..4652e46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,10 +7,7 @@ use crate::week_one::{ day_two, }; -use crate::week_two::day_four::{ - convert_f_to_c, - generate_fibonacci_num -}; +use crate::week_two::day_one::{convert_f_to_c, generate_fibonacci_num}; fn main() { day_one::main(); diff --git a/src/week_two.rs b/src/week_two.rs index 50db8e2..bce4cc7 100644 --- a/src/week_two.rs +++ b/src/week_two.rs @@ -1 +1 @@ -pub mod day_four; \ No newline at end of file +pub mod day_one; \ No newline at end of file diff --git a/src/week_two/day_four.rs b/src/week_two/day_one.rs similarity index 100% rename from src/week_two/day_four.rs rename to src/week_two/day_one.rs