My solutions for Advent of Code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
adventofcode/2022/src/helpers.rs

21 lines
518 B

/*
* Use this file if you want to extract helpers from your solutions.
* Example import from this file: `use advent_of_code::helpers::example_fn;`.
*/
pub fn parse_input<T>(input: &str, cons: fn(&str) -> T) -> Vec<T>
where
Vec<T>: FromIterator<T>,
{
input.lines().map(cons).collect()
}
pub fn transpose<T>(v: Vec<Vec<T>>) -> Vec<Vec<T>>
where
T: Clone,
{
assert!(!v.is_empty());
(0..v[0].len())
.map(|i| v.iter().map(|inner| inner[i].clone()).collect::<Vec<T>>())
.collect()
}