This commit is contained in:
2022-12-03 05:50:33 +00:00
parent 8ae82163b4
commit e54aad2d33
6 changed files with 366 additions and 10 deletions

View File

@ -1,23 +1,47 @@
use crate::read;
fn val(c: char) -> u32 {
if c.is_lowercase() {
c as u32 - 96
} else {
26 + c as u32 - 64
}
}
pub fn run() {
let input = read("02");
let lines = input
.lines()
.map(|l| {
l
});
let input = read("03");
#[cfg(feature = "part1")]
{
let a = "TODO";
eprintln!("Day 2, Part 01: {}", a);
let lines: u32 = input
.lines()
.map(|l| {
let l = l.to_string();
let len = l.len() / 2;
let left = &l[0..len];
let right = &l[len..];
let lc = left.chars().find(|c| right.chars().any(|rc| rc == *c));
val(lc.unwrap())
})
.sum();
println!("Day 2, Part 01: {}", lines);
}
#[cfg(feature = "part2")]
{
let b = "TODO";
eprintln!("Day 2, Part 02: {}", b);
let lines: u32 = input.lines().collect::<Vec<_>>()[..] // Not a fan of collect here
.chunks(3)
.map(|l| {
let first = l[0];
let second = l[1];
let third = l[2];
let common = first
.chars()
.find(|f| second.chars().any(|s| s == *f) && third.chars().any(|t| t == *f));
val(common.unwrap())
})
.sum();
println!("Day 2, Part 02: {}", lines);
}
}