1
0

Added Day 3 part 2

This commit is contained in:
Ishan Jain 2022-12-03 10:50:47 +05:30
parent 9754d4ce00
commit d72956e0f6
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27

View File

@ -6,13 +6,10 @@ const INPUTS: [&str; 2] = [
include_str!("../inputs/input.txt"), include_str!("../inputs/input.txt"),
]; ];
fn parse(input: &'static str) -> impl Iterator<Item = (&str, &str)> { fn parse(input: &'static str) -> Vec<(&str, &str, &str)> {
input.trim().lines().map(|line| { let lines: Vec<&str> = input.trim().lines().collect();
let l = line.len();
let (a, b) = line.split_at(l / 2);
(a, b) lines.chunks(3).map(|a| (a[0], a[1], a[2])).collect()
})
} }
fn main() { fn main() {
@ -24,17 +21,23 @@ fn main() {
} }
} }
fn solution<'a>(input: impl Iterator<Item = (&'a str, &'a str)>) -> usize { fn solution<'a>(input: Vec<(&'a str, &'a str, &'a str)>) -> usize {
let mut score = 0; let mut score = 0;
for (a, b) in input { for (a, b, c) in input {
let ai = find_items(a); let ai = find_items(a);
let bi = find_items(b); let bi = find_items(b);
let ci = find_items(c);
let mut intersect = [false; 256]; let mut intersect = [false; 256];
for (i, (x, y)) in ai.into_iter().zip(bi.into_iter()).enumerate() { for (i, ((x, y), z)) in ai
if x & y { .into_iter()
.zip(bi.into_iter())
.zip(ci.into_iter())
.enumerate()
{
if x & y & z {
intersect[i] = true; intersect[i] = true;
} }
} }