diff options
| author | Aleksa Vuckovic <aleksa@vuckovic.cc> | 2023-12-07 03:06:25 +0100 |
|---|---|---|
| committer | Aleksa Vuckovic <aleksa@vuckovic.cc> | 2023-12-07 03:06:25 +0100 |
| commit | ff58eb7f8744beff4ff1157f9e169b9b827db611 (patch) | |
| tree | 0cc477c18ffa2c2e0d54658f66e3d5dc9c653f54 | |
| parent | 2a70e529992fa08bdda87ca7e663730b97fb8e8c (diff) | |
day6
| -rw-r--r-- | input/day6.txt | 2 | ||||
| -rw-r--r-- | src/day6pt1.rs | 29 | ||||
| -rw-r--r-- | src/day6pt2.rs | 23 | ||||
| -rw-r--r-- | src/main.rs | 4 |
4 files changed, 56 insertions, 2 deletions
diff --git a/input/day6.txt b/input/day6.txt new file mode 100644 index 0000000..2214cba --- /dev/null +++ b/input/day6.txt @@ -0,0 +1,2 @@ +Time: 51 69 98 78 +Distance: 377 1171 1224 1505 diff --git a/src/day6pt1.rs b/src/day6pt1.rs new file mode 100644 index 0000000..0ea45b7 --- /dev/null +++ b/src/day6pt1.rs @@ -0,0 +1,29 @@ +pub fn main() { + let txt = std::fs::read_to_string("./input/day6.txt").unwrap(); + let lines: Vec<_> = txt + .lines() + .map(|s| { + s.split(":") + .collect::<Vec<_>>() + .get(1) + .unwrap() + .split(" ") + .filter(|&x| !x.is_empty()) + .map(|r| r.parse::<u32>().unwrap()) + .collect::<Vec<_>>() + }) + .collect(); + + let mut p: u32 = 1; + for i in 0..lines[0].len() { + let mut sum: u32 = 0; + for j in 1..lines[0][i] { + if (lines[0][i] - j) * j > lines[1][i] { + sum += 1; + } + } + p *= sum; + } + + println!("{:?}", p); +} diff --git a/src/day6pt2.rs b/src/day6pt2.rs new file mode 100644 index 0000000..867bd49 --- /dev/null +++ b/src/day6pt2.rs @@ -0,0 +1,23 @@ +pub fn main() { + let txt = std::fs::read_to_string("./input/day6.txt").unwrap(); + let lines: Vec<_> = txt + .lines() + .map(|s| { + s.split(":") + .collect::<Vec<_>>() + .get(1) + .unwrap() + .replace(" ", "") + }) + .map(|s| s.parse::<u64>().unwrap()) + .collect(); + + let mut sum: u64 = 0; + for j in 1..lines[0] { + if (lines[0] - j) * j > lines[1] { + sum += 1; + } + } + + println!("{:?}", sum); +} diff --git a/src/main.rs b/src/main.rs index b3ad2f6..1eae0ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -mod day5pt2; +mod day6pt2; fn main() { - day5pt2::main(); + day6pt2::main(); } |
