From db2686c798378738020a0951a521358586e21aa0 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 9 Feb 2024 11:42:04 +0100 Subject: Add day2 in OCaml --- 2023/day6/Cargo.toml | 8 ---- 2023/day6/example.txt | 2 - 2023/day6/input.txt | 3 -- 2023/day6/src/lib.rs | 102 -------------------------------------------------- 4 files changed, 115 deletions(-) delete mode 100644 2023/day6/Cargo.toml delete mode 100644 2023/day6/example.txt delete mode 100644 2023/day6/input.txt delete mode 100644 2023/day6/src/lib.rs (limited to '2023/day6') diff --git a/2023/day6/Cargo.toml b/2023/day6/Cargo.toml deleted file mode 100644 index 89d04ae..0000000 --- a/2023/day6/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "day6" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/2023/day6/example.txt b/2023/day6/example.txt deleted file mode 100644 index 28f5ae9..0000000 --- a/2023/day6/example.txt +++ /dev/null @@ -1,2 +0,0 @@ -Time: 7 15 30 -Distance: 9 40 200 diff --git a/2023/day6/input.txt b/2023/day6/input.txt deleted file mode 100644 index f4a8fdc..0000000 --- a/2023/day6/input.txt +++ /dev/null @@ -1,3 +0,0 @@ -Time: 41 66 72 66 -Distance: 244 1047 1228 1040 - diff --git a/2023/day6/src/lib.rs b/2023/day6/src/lib.rs deleted file mode 100644 index b3e33cb..0000000 --- a/2023/day6/src/lib.rs +++ /dev/null @@ -1,102 +0,0 @@ -pub fn part1(input: &str) -> u64 { - let mut res: u64 = 1; - - let td: Vec> = input - .trim_end() - .split('\n') - .map(|x| { - x.split(':') - .nth(1) - .unwrap() - .trim() - .replace(" ", " ") - .replace(" ", " ") - .replace(" ", " ") - .split(' ') - .map(|y| y.parse::().unwrap()) - .collect() - }) - .collect(); - - assert_eq!(td.len(), 2); - let (t, d) = (&td[0], &td[1]); - - for i in 0..t.len() { - let mut r = 0; - for j in 0..t[i] { - if (t[i] - j) * j > d[i] { - r += 1; - } - } - res *= r; - } - - res -} - -pub fn part2(input: &str) -> u64 { - let mut res: u64 = 1; - - let td: Vec> = input - .trim_end() - .split('\n') - .map(|x| { - x.split(':') - .nth(1) - .unwrap() - .trim() - .replace(" ", "") - .split(' ') - .map(|y| y.parse::().unwrap()) - .collect() - }) - .collect(); - - assert_eq!(td.len(), 2); - let (t, d) = (&td[0], &td[1]); - - for i in 0..t.len() { - let mut r = 0; - for j in 0..t[i] { - if (t[i] - j) * j > d[i] { - r += 1; - } - } - res *= r; - } - - res -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn example_part1() { - let input = include_str!("../example.txt"); - let result = part1(input); - assert_eq!(result, 288); - } - - #[test] - fn input_part1() { - let input = include_str!("../input.txt"); - let result = part1(input); - assert_eq!(result, 74698); - } - - #[test] - fn example_part2() { - let input = include_str!("../example.txt"); - let result = part2(input); - assert_eq!(result, 71503); - } - - #[test] - fn input_part2() { - let input = include_str!("../input.txt"); - let result = part2(input); - assert_eq!(result, 27563421); - } -} -- cgit v1.2.3-18-g5258