minor cleanup
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Vivian 2022-12-11 12:23:57 +01:00
parent 4c169aeb4a
commit 14296cb1ba
4 changed files with 28 additions and 52 deletions

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# Advent of Code 2022
These are my solutions to AoC 2022 written in Rust

View file

@ -1,39 +0,0 @@
use eyre::Result;
use itertools::Itertools;
const DAY: usize = 0;
pub fn part1(example: bool) -> Result<usize> {
let input = crate::input(DAY, example)?;
Ok(0)
}
pub fn part2(example: bool) -> Result<usize> {
let input = crate::input(DAY, example)?;
Ok(0)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn part1_example() {
assert_eq!(part1(true).unwrap(), 0);
}
#[test]
fn part1_real() {
assert_eq!(part1(false).unwrap(), 0);
}
#[test]
fn part2_example() {
assert_eq!(part2(true).unwrap(), 0);
}
#[test]
fn part2_real() {
assert_eq!(part2(false).unwrap(), 0);
}
}

View file

@ -104,7 +104,7 @@ fn draw(cycle: isize, x: isize, out: &mut [bool]) {
}
}
pub fn part2(example: bool) -> Result<()> {
pub fn part2(example: bool) -> Result<String> {
let input = crate::input(DAY, example)?;
let instrs = parse(&input);
let mut result = vec![false; 240];
@ -114,14 +114,16 @@ pub fn part2(example: bool) -> Result<()> {
})
.run();
let mut output = String::with_capacity(240);
for chunk in result.chunks(40) {
for pixel in chunk {
print!("{}", if *pixel { "#" } else { " " });
output.push(if *pixel { '#' } else { ' ' })
}
println!();
output.push('\n');
}
Ok(())
Ok(output)
}
#[cfg(test)]
@ -140,11 +142,11 @@ mod tests {
#[test]
fn part2_example() {
assert_eq!(part2(true).unwrap(), ());
assert_eq!(part2(true).unwrap(), "## ## ## ## ## ## ## ## ## ## \n### ### ### ### ### ### ### \n#### #### #### #### #### \n##### ##### ##### ##### \n###### ###### ###### ####\n####### ####### ####### \n");
}
#[test]
fn part2_real() {
assert_eq!(part2(false).unwrap(), ());
assert_eq!(part2(false).unwrap(), "### # # # # # # ### #### # # \n# # # # # # # # # # # # # \n# # # # # # ## ### # #### \n### # # # # # # # # # # # \n# # # # # # # # # # # # \n# #### ## #### # # ### #### # # \n");
}
}

View file

@ -1,5 +1,3 @@
use std::vec;
use eyre::Result;
use itertools::Itertools;
use minmaxn::MinMaxN;
@ -103,7 +101,8 @@ fn turn(monkeys: &mut [Monkey], num: usize, mut op: impl FnMut(usize) -> usize)
monkeys[m.if_false].items.push(item)
}
}
monkeys[num].items = vec![];
monkeys[num].items.clear();
}
fn round(monkeys: &mut Vec<Monkey>, mut op: impl FnMut(usize) -> usize) {
@ -120,9 +119,15 @@ pub fn part1(example: bool) -> Result<usize> {
round(&mut monkeys, |x| x / 3);
}
let [m1, m2] = monkeys.iter().map(|m| m.inspections).max_n();
let m = monkeys
.iter()
.map(|m| m.inspections)
.max_n::<2>()
.into_iter()
.flatten()
.product();
Ok(m1.unwrap() * m2.unwrap())
Ok(m)
}
pub fn part2(example: bool) -> Result<usize> {
@ -135,9 +140,15 @@ pub fn part2(example: bool) -> Result<usize> {
round(&mut monkeys, |x| x % lcm);
}
let [m1, m2] = monkeys.iter().map(|m| m.inspections).max_n();
let m = monkeys
.iter()
.map(|m| m.inspections)
.max_n::<2>()
.into_iter()
.flatten()
.product();
Ok(m1.unwrap() * m2.unwrap())
Ok(m)
}
#[cfg(test)]