summaryrefslogtreecommitdiff
path: root/2023/day6
diff options
context:
space:
mode:
Diffstat (limited to '2023/day6')
-rw-r--r--2023/day6/Cargo.toml8
-rw-r--r--2023/day6/example.txt2
-rw-r--r--2023/day6/input.txt3
-rw-r--r--2023/day6/src/lib.rs102
4 files changed, 0 insertions, 115 deletions
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<Vec<_>> = input
- .trim_end()
- .split('\n')
- .map(|x| {
- x.split(':')
- .nth(1)
- .unwrap()
- .trim()
- .replace(" ", " ")
- .replace(" ", " ")
- .replace(" ", " ")
- .split(' ')
- .map(|y| y.parse::<u64>().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<Vec<_>> = input
- .trim_end()
- .split('\n')
- .map(|x| {
- x.split(':')
- .nth(1)
- .unwrap()
- .trim()
- .replace(" ", "")
- .split(' ')
- .map(|y| y.parse::<u64>().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);
- }
-}