Wrote program for Day 4

This commit is contained in:
Mariano Riefolo 2024-07-29 15:57:03 +02:00
parent 0dc867ecb5
commit 539eddce01
4 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,6 @@
[package]
name = "is_johnny_making_progress"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,11 @@
pub fn progress_days(days: &'static [usize]) -> usize {
let mut progress_days = 0;
for i in 1..days.len() {
if days[i] > days[i-1] {
progress_days += 1;
}
}
progress_days
}

View File

@ -0,0 +1,3 @@
fn main() {
println!("Run `cargo test`.");
}

View File

@ -0,0 +1,21 @@
use is_johnny_making_progress::progress_days;
#[test]
fn no_progress_days() {
assert_eq!(progress_days(&[9, 9]), 0);
}
#[test]
fn one_progress_day() {
assert_eq!(progress_days(&[6, 5, 4, 3, 2, 9]), 1);
}
#[test]
fn two_progress_days() {
assert_eq!(progress_days(&[3, 4, 1, 2]), 2);
}
#[test]
fn three_progress_days() {
assert_eq!(progress_days(&[10, 11, 12, 9, 10]), 3);
}