Merge branch 'day-15'

This commit is contained in:
Kristofers Solo 2023-12-16 20:52:38 +02:00
commit 6bda6e80c7
7 changed files with 74 additions and 0 deletions

10
2023/day-15/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "day-15"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
color-eyre.workspace = true
itertools.workspace = true

1
2023/day-15/input.txt Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,9 @@
use color_eyre::Result;
use day_15::part1::process;
fn main() -> Result<()> {
let file = include_str!("../../input.txt");
let result = process(file)?;
println!("{}", result);
Ok(())
}

View File

@ -0,0 +1,9 @@
use color_eyre::Result;
use day_15::part2::process;
fn main() -> Result<()> {
let file = include_str!("../../input.txt");
let result = process(file)?;
println!("{}", result);
Ok(())
}

2
2023/day-15/src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod part1;
pub mod part2;

24
2023/day-15/src/part1.rs Normal file
View File

@ -0,0 +1,24 @@
use color_eyre::Result;
pub fn process(input: &str) -> Result<usize> {
let num = input
.split(",")
.map(|hash| {
hash.chars()
.fold(0, |acc, next_char| (acc + (next_char as usize)) * 17 % 256)
})
.sum();
Ok(num)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_process() -> Result<()> {
let input = "rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7";
assert_eq!(1320, process(input)?);
Ok(())
}
}

19
2023/day-15/src/part2.rs Normal file
View File

@ -0,0 +1,19 @@
use color_eyre::Result;
pub fn process(input: &str) -> Result<usize> {
todo!("day xx - part 2");
Ok(0)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_process() -> Result<()> {
let input = "";
todo!("haven't built test yet");
assert_eq!(0, process(input)?);
Ok(())
}
}